Skip to content

Commit

Permalink
Revert "Fixed required validation considering false value falsy"
Browse files Browse the repository at this point in the history
This reverts commit a100e98.
  • Loading branch information
travist committed Apr 18, 2024
1 parent 91652c2 commit bc09287
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 51 deletions.
50 changes: 0 additions & 50 deletions src/process/validation/rules/__tests__/validateRequired.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,6 @@ it('Validating a simple component that is required and present in the data will
expect(result).to.equal(null);
});


it('Validating a simple radio component that is required and present in the data with value set to false will return null', async () => {
const component = { ...simpleRadioField, validate: { required: true }, values: [
{
label: 'Yes',
value: 'true',
},
{
label: 'No',
value: 'false',
}] };
const data = { component: false };
const context = generateProcessorContext(component, data);
const result = await validateRequired(context);
expect(result).to.equal(null);
});


it('Validating a simple selectbox that is required and present in the data with value set to zero will return null', async () => {
const component = { ...simpleSelectBoxes, validate: { required: true }, values: [
{
label: 'true',
value: 'true',
},
{
label: 'Null',
value: '0',
}] };
const data = { component: 0 };
const context = generateProcessorContext(component, data);
const result = await validateRequired(context);
expect(result).to.equal(null);
});

it('Validating a simple selectbox that is required and present in the data with value set to false will return null', async () => {
const component = { ...simpleSelectBoxes, validate: { required: true }, values: [
{
label: 'true',
value: 'true',
},
{
label: 'false',
value: 'false',
}] };
const data = { component: false };
const context = generateProcessorContext(component, data);
const result = await validateRequired(context);
expect(result).to.equal(null);
});

it('Validating a simple component that is not required and present in the data will return null', async () => {
const component = simpleTextField;
const data = { component: 'a simple value' };
Expand Down
2 changes: 1 addition & 1 deletion src/process/validation/rules/validateRequired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const validateRequiredSync: RuleFnSync = (context: ValidationContext) =>
return null;
}
if (
(value === null || value === undefined || isEmptyObject(value) || (!!value === false && value !== 0 && value !== false )) &&
(value === null || value === undefined || isEmptyObject(value) || (!!value === false && value !== 0)) &&
!component.hidden
) {
return error;
Expand Down

0 comments on commit bc09287

Please sign in to comment.