Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-9244: fixed an issue where Radio component with Allow only available values checked does not submit #178

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,11 @@ describe('validateAvailableItems', function () {
context.fetch = () => {
return Promise.resolve({
ok: true,
json: () => Promise.resolve(['1', '2', '3']),
json: () => Promise.resolve([
{ label: '1', value: '1' },
{ label: '2', value: '2' },
{ label: '3', value: '3' },
]),
});
};
const result = await validateAvailableItems(context);
Expand All @@ -501,7 +505,11 @@ describe('validateAvailableItems', function () {
context.fetch = () => {
return Promise.resolve({
ok: true,
json: () => Promise.resolve(['1', '2', '3']),
json: () => Promise.resolve([
{ label: '1', value: '1' },
{ label: '2', value: '2' },
{ label: '3', value: '3' },
]),
});
};
const result = await validateAvailableItems(context);
Expand Down
5 changes: 4 additions & 1 deletion src/process/validation/rules/validateAvailableItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ export const validateAvailableItems: RuleFn = async (context: ValidationContext)
? null
: error;
}
return values.find((optionValue) => optionValue === value) !== undefined ? null : error;
Copy link
Contributor

@brendanbond brendanbond Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cover the case of, like, custom values? Should we be doing a deep equal here instead? I want to make sure all of our bases are covered (i.e. custom values or JSON values of any shape)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brendanbond There is a check above this line for the object value, I'm pretty sure it should cover most of the json and custom values, so this line is only triggered for primitive ones. I changed it a bit to pass both validation in case if dataSrc=values and if values is an array of primitives. So all the bases seem to be covered, but we can further discuss this if you have any other adjustments in mind.

return values.find((optionValue) => optionValue.value === value || optionValue === value) !==
undefined
? null
: error;
}

return null;
Expand Down
Loading