mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 12:32:34 +10:00
Adds custom font sizes to fields https://github.com/user-attachments/assets/1473a4d7-8dc6-4ead-acf5-dd78be7782a0
34 lines
917 B
TypeScript
34 lines
917 B
TypeScript
import type { TTextFieldMeta as TextFieldMeta } from '../types/field-meta';
|
|
|
|
export const validateTextField = (
|
|
value: string,
|
|
fieldMeta: TextFieldMeta,
|
|
isSigningPage: boolean = false,
|
|
): string[] => {
|
|
const errors = [];
|
|
|
|
const { characterLimit, readOnly, required, fontSize } = 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');
|
|
}
|
|
|
|
if (fontSize && (fontSize < 8 || fontSize > 96)) {
|
|
errors.push('Font size must be between 8 and 96.');
|
|
}
|
|
|
|
return errors;
|
|
};
|