Skip to content

Commit b6824df

Browse files
committed
Fixing binding between engine and web forms
1 parent a9a724c commit b6824df

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

packages/web-forms/src/components/controls/RankControl.vue

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ interface RankControlProps {
99
readonly question: RankNode;
1010
}
1111
12+
interface RankDraggableOption {
13+
value: string;
14+
label: string;
15+
}
16+
1217
const props = defineProps<RankControlProps>();
1318
const HOLD_DELAY = 60; // Delay in ms to hold an item before dragging, avoids accidental reordering on swipe.
14-
const options = ref([]);
19+
const options = ref<RankDraggableOption[]>([]);
1520
const touched = ref(false);
1621
const submitPressed = inject<boolean>('submitPressed');
1722
const highlight = {
@@ -20,18 +25,15 @@ const highlight = {
2025
};
2126
2227
const transformOptions = (rankOptions: RankItem[]) => {
23-
options.value = rankOptions.map((option) => {
24-
const value = option.value;
25-
const valueOption = props.question.getValueOption(value);
26-
27-
if (valueOption == null) {
28-
throw new RankFunctionalityError(`Failed to find option for value: ${value}`);
29-
}
28+
if (options.value.length) {
29+
options.value.forEach((option) => {
30+
option.label = props.question.getValueLabel(option.value);
31+
});
32+
return;
33+
}
3034
31-
return {
32-
value,
33-
label: valueOption.label.asString,
34-
};
35+
options.value = rankOptions.map((option) => {
36+
return { value: option.value, label: props.question.getValueLabel(option.value) };
3537
});
3638
};
3739

packages/xforms-engine/src/client/RankNode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export interface RankNodeState extends BaseValueNodeState<readonly string[]> {
1717
get valueOptions(): RankValueOptions;
1818

1919
/**
20-
* This value is an ordered collection of {@link RankItem}s.
21-
* The order of the items is important and should be preserved during processing.
20+
* An ordered collection of values from {@link RankItem}.
21+
* The order of the items is important and must be preserved during processing.
2222
*/
2323
get value(): readonly string[];
2424
}
@@ -37,12 +37,12 @@ export interface RankNode extends BaseValueNode<'string', readonly string[]> {
3737
readonly validationState: LeafNodeValidationState;
3838

3939
/**
40-
* Convenience API to get the value which is an ordered collection of {@link RankItem}s.
40+
* Convenience API to get the {@link RankItem}'s label.
4141
*/
42-
getValueOption(value: string): RankItem | null;
42+
getValueLabel(value: string): string;
4343

4444
/**
45-
* Set the value which is an ordered collection of {@link RankItem}s.
45+
* Set the value which is an ordered collection of values from {@link RankItem}.
4646
* Calling this setter replaces the currently value.
4747
* If called with an empty array, the current is cleared.
4848
*/

packages/xforms-engine/src/instance/RankControl.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,9 @@ export class RankControl
134134
this.currentState = state.currentState;
135135
}
136136

137-
/**
138-
* This method is a client-facing convenience API for reading state,
139-
* so it **MUST** read from client-reactive state!
140-
* @param value
141-
*/
142-
getValueOption(value: string): RankItem | null {
137+
getValueLabel(value: string): string {
143138
const valueOption = this.currentState.valueOptions.find(item => item.value === value);
144-
return valueOption ?? null;
139+
return valueOption.label.asString;
145140
}
146141

147142
setValues(valuesInOrder: readonly string[]): Root {

0 commit comments

Comments
 (0)