Skip to content

Commit

Permalink
implement patternMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Apr 16, 2024
1 parent b9ebc0a commit 3acbc0c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/process/validation/rules/validateRegexPattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ export const validateRegexPattern: RuleFn = async (context: ValidationContext) =

export const validateRegexPatternSync: RuleFnSync = (context: ValidationContext) => {
const { component, value } = context;
if (!shouldValidate(context)) {
if (!shouldValidate(context) || !isValidatableTextFieldComponent(component)) {
return null;
}

const pattern = (component as TextAreaComponent).validate?.pattern;
const regex = new RegExp(`^${pattern}$`);
return typeof value === 'string' && regex.test(value)
? null
: new FieldError('pattern', { ...context, regex: pattern, pattern: pattern, setting: pattern });
: new FieldError(component.validate?.pattern || 'pattern', { ...context, regex: pattern, pattern: pattern, setting: pattern }, 'pattern');
};

export const validateRegexPatternInfo: ProcessorInfo<ValidationContext, FieldError | null> = {
name: 'validateRegexPattern',
process: validateRegexPattern,
processSync: validateRegexPatternSync,
shouldProcess: shouldValidate,
};
};

0 comments on commit 3acbc0c

Please sign in to comment.