mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
@ -1,3 +1,5 @@
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { checkboxValidationSigns } from '@documenso/ui/primitives/document-flow/field-items-advanced-settings/constants';
|
||||
|
||||
import type { TCheckboxFieldMeta } from '../types/field-meta';
|
||||
@ -75,3 +77,15 @@ export const validateCheckboxField = (
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
export const validateCheckboxLength = (
|
||||
numberOfSelectedOptions: number,
|
||||
validationRule: '>=' | '=' | '<=',
|
||||
validationLength: number,
|
||||
) => {
|
||||
return match(validationRule)
|
||||
.with('>=', () => numberOfSelectedOptions >= validationLength)
|
||||
.with('=', () => numberOfSelectedOptions === validationLength)
|
||||
.with('<=', () => numberOfSelectedOptions <= validationLength)
|
||||
.exhaustive();
|
||||
};
|
||||
|
||||
@ -29,7 +29,7 @@ export const validateNumberField = (
|
||||
errors.push('Value is required');
|
||||
}
|
||||
|
||||
if (!/^[0-9,.]+$/.test(value.trim())) {
|
||||
if ((isSigningPage || value.length > 0) && !/^[0-9,.]+$/.test(value.trim())) {
|
||||
errors.push(`Value is not a valid number`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user