diff --git a/src/process/validation/rules/__tests__/validateAvailableItems.test.ts b/src/process/validation/rules/__tests__/validateAvailableItems.test.ts index cc5beaba..a227646c 100644 --- a/src/process/validation/rules/__tests__/validateAvailableItems.test.ts +++ b/src/process/validation/rules/__tests__/validateAvailableItems.test.ts @@ -473,11 +473,15 @@ it('Validating a simple radio component with url data source with the available }; const context = generateProcessorContext(component, data); - context.fetch = (url: string, options?: RequestInit | undefined) => { - return Promise.resolve({ - ok: true, - json: () => Promise.resolve(['1', '2', '3']) - }); + context.fetch = () => { + return Promise.resolve({ + ok: true, + json: () => Promise.resolve([ + { label: '1', value: '1' }, + { label: '2', value: '2' }, + { label: '3', value: '3' }, + ]), + }); }; const result = await validateAvailableItems(context); expect(result).to.equal(null); @@ -498,11 +502,15 @@ it('Validating a simple radio component with url data source with the available }; const context = generateProcessorContext(component, data); - context.fetch = (url: string, options?: RequestInit | undefined) => { - return Promise.resolve({ - ok: true, - json: () => Promise.resolve(['1', '2', '3']) - }); + context.fetch = () => { + return Promise.resolve({ + ok: true, + json: () => Promise.resolve([ + { label: '1', value: '1' }, + { label: '2', value: '2' }, + { label: '3', value: '3' }, + ]), + }); }; const result = await validateAvailableItems(context); expect(result).to.be.instanceOf(FieldError); diff --git a/src/process/validation/rules/validateAvailableItems.ts b/src/process/validation/rules/validateAvailableItems.ts index 64c361b9..2be1a732 100644 --- a/src/process/validation/rules/validateAvailableItems.ts +++ b/src/process/validation/rules/validateAvailableItems.ts @@ -230,16 +230,22 @@ export const validateAvailableItems: RuleFn = async (context: ValidationContext) return null; } - const values = component.dataSrc === 'url' ? await getAvailableDynamicValues(component, context) : component.values; - if (values) { - if (isObject(value)) { - return values.find((optionValue) => compareComplexValues(optionValue, value, context)) !== - undefined - ? null - : error; - } - return values.find((optionValue) => optionValue === value) !== undefined ? null : error; - } + const values = + component.dataSrc === 'url' + ? await getAvailableDynamicValues(component, context) + : component.values; + if (values) { + if (isObject(value)) { + return values.find((optionValue) => compareComplexValues(optionValue, value, context)) !== + undefined + ? null + : error; + } + return values.find((optionValue) => optionValue.value === value || optionValue === value) !== + undefined + ? null + : error; + } return null; } else if (isValidateableSelectComponent(component)) {