react-hook-form#RegisterOptions TypeScript Examples
The following examples show how to use
react-hook-form#RegisterOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: formValidationOptions.ts From atlas with GNU General Public License v3.0 | 7 votes |
textFieldValidation = ({
name,
minLength = 0,
maxLength,
required = false,
pattern,
patternMessage,
validate,
}: TextValidationArgs): RegisterOptions => ({
required: {
value: required,
message: `${name} cannot be empty`,
},
minLength: {
value: minLength,
message: `${name} must be at least ${minLength} characters`,
},
maxLength: {
value: maxLength,
message: `${name} cannot be longer than ${maxLength} characters`,
},
...(pattern
? {
pattern: {
value: pattern,
message: patternMessage ? `${name} ${patternMessage}` : `${name} must be valid`,
},
}
: {}),
validate,
})
Example #2
Source File: validation.ts From yasd with MIT License | 7 votes |
export function getValidationHint(
typeMap: {
[key in keyof RegisterOptions]?: string
} & {
[key: string]: any
},
fieldError?: FieldError,
): string | undefined {
if (!fieldError) return undefined
for (const key in typeMap) {
if (fieldError.type === key) {
return typeMap[key]
}
}
return fieldError.message
}
Example #3
Source File: formValidationOptions.ts From atlas with GNU General Public License v3.0 | 6 votes |
requiredValidation: (name: string) => RegisterOptions = (name) => ({
required: {
value: true,
message: `${name} must be selected`,
},
})