mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
chore: add more field types (#1141)
Adds a number of new field types and capabilities to existing fields. A massive change with far too many moving pieces to document in a single commit.
This commit is contained in:
33
packages/lib/advanced-fields-validation/validate-text.ts
Normal file
33
packages/lib/advanced-fields-validation/validate-text.ts
Normal file
@ -0,0 +1,33 @@
|
||||
interface TextFieldMeta {
|
||||
characterLimit?: number;
|
||||
readOnly?: boolean;
|
||||
required?: boolean;
|
||||
}
|
||||
|
||||
export const validateTextField = (
|
||||
value: string,
|
||||
fieldMeta: TextFieldMeta,
|
||||
isSigningPage: boolean = false,
|
||||
): string[] => {
|
||||
const errors = [];
|
||||
|
||||
const { characterLimit, readOnly, required } = fieldMeta;
|
||||
|
||||
if (required && !value && isSigningPage) {
|
||||
errors.push('Value is required');
|
||||
}
|
||||
|
||||
if (characterLimit !== undefined && characterLimit > 0 && value.length > characterLimit) {
|
||||
errors.push(`Value length (${value.length}) exceeds the character limit (${characterLimit})`);
|
||||
}
|
||||
|
||||
if (readOnly && value.length < 1) {
|
||||
errors.push('A read-only field must have text');
|
||||
}
|
||||
|
||||
if (readOnly && required) {
|
||||
errors.push('A field cannot be both read-only and required');
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
Reference in New Issue
Block a user