Skip to content

Commit

Permalink
Merge pull request #90 from formio/FIO-8288-calendar-widget-validation
Browse files Browse the repository at this point in the history
FIO-8288: do not validate dates in textfield components with calendar widgets
  • Loading branch information
AlexeyNikipelau authored May 21, 2024
2 parents 259ec9b + de0118a commit ab8cc84
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
36 changes: 2 additions & 34 deletions src/process/validation/rules/__tests__/validateDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,12 @@ it('Validating a textField calendar picker component with no data will return nu
expect(result).to.equal(null);
});

it('Validating a textField calendar picker component with an invalid date string value will return a FieldError', async () => {
it('Textfield calendar picker component date values should not be validated and return null', async () => {
const component = calendarTextField;
const data = {
component: 'hello, world!',
};
const context = generateProcessorContext(component, data);
const result = await validateDate(context);
expect(result).to.be.instanceOf(FieldError);
expect(result?.errorKeyOrMessage).to.equal('invalidDate');
});

it('Validating a textField calendar picker component with an valid date string value will return null', async () => {
const component = calendarTextField;
const data = {
component: '2023-03-09T12:00:00-06:00',
};
const context = generateProcessorContext(component, data);
const result = await validateDate(context);
expect(result).to.equal(null);
});

it('Validating a textField calendar picker component with an invalid Date object will return a FieldError', async () => {
const component = calendarTextField;
const data = {
component: new Date('Hello, world!'),
};
const context = generateProcessorContext(component, data);
const result = await validateDate(context);
expect(result).to.be.instanceOf(FieldError);
expect(result?.errorKeyOrMessage).to.equal('invalidDate');
});

it('Validating a textField calendar picker component with a valid Date object will return null', async () => {
const component = calendarTextField;
const data = {
component: new Date(),
};
const context = generateProcessorContext(component, data);
const result = await validateDate(context);
expect(result).to.equal(null);
expect(result).to.be.equal(null);
});
6 changes: 1 addition & 5 deletions src/process/validation/rules/validateDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ const isValidatableDateTimeComponent = (obj: any): obj is DateTimeComponent => {
return !!obj && !!obj.type && obj.type === 'datetime';
};

const isValidatableTextFieldComponent = (obj: any): obj is TextFieldComponent => {
return !!obj && !!obj.type && obj.widget && obj.widget.type === 'calendar';
};

const isValidatable = (component: any) => {
return isValidatableDateTimeComponent(component) || isValidatableTextFieldComponent(component);
return isValidatableDateTimeComponent(component);
};

export const shouldValidate = (context: ValidationContext) => {
Expand Down

0 comments on commit ab8cc84

Please sign in to comment.