Skip to content

Commit

Permalink
FIO-8347: added ability to skip mask validation
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-formio committed Jun 27, 2024
1 parent c859404 commit 551a3e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/process/validation/rules/__tests__/validateMask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,17 @@ it('Validating a mutil-mask component should return null if the value matches th
result = await validateMask(context);
expect(result).to.equal(null);
});

it('Validating a mask component should return null if the instance contains a skipMaskValidation property', async () => {
const component = { ...simpleTextField, inputMask: '999-999-9999' };
const data = {
component: '1234',
};
const context = generateProcessorContext(component, data);
let result = await validateMask(context);
expect(result).to.be.instanceOf(FieldError);
expect(result?.errorKeyOrMessage).to.equal('mask');
(context as any).instance = { skipMaskValidation: true };
result = await validateMask(context);
expect(result).to.equal(null);
});
4 changes: 2 additions & 2 deletions src/process/validation/rules/validateMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export function matchInputMask(value: any, inputMask: any) {
}

export const shouldValidate = (context: ValidationContext) => {
const { component, value } = context;
if (!isValidatableComponent(component) || !value) {
const { component, value, instance } = context;
if ((instance as any)?.skipMaskValidation || !isValidatableComponent(component) || !value) {
return false;
}
if (value == null) {
Expand Down

0 comments on commit 551a3e7

Please sign in to comment.