| 1 |
/** |
| 2 |
* Builds the expected registration options from the Field API validation rules |
| 3 |
* |
| 4 |
* @since 3.0.0 |
| 5 |
*/ |
| 6 |
import {RegisterOptions} from 'react-hook-form'; |
| 7 |
|
| 8 |
export default function buildRegisterValidationOptions(validationRules: {[key: string]: any}): RegisterOptions { |
| 9 |
return ['required', 'maxLength', 'minLength'].reduce((rules, rule) => { |
| 10 |
if (validationRules.hasOwnProperty(rule)) { |
| 11 |
rules[rule] = validationRules[rule]; |
| 12 |
} |
| 13 |
|
| 14 |
return rules; |
| 15 |
}, {}); |
| 16 |
} |
| 17 |
|