obss
logo
github_iconnpm_iconVersion: 5.0.2
rules
const rules = [ { listPath: 'listChild', subRules: [ { path: 'subkey1', ruleSet: ['required', { rule: 'length', greaterThan: 3 }], disableFocusAfterSubmit: true, }, { path: 'subkey2', ruleSet: [ { rule: 'required', disableIf: disableSubkey2, }, { rule: 'number', greaterThan: 5, disableIf: disableSubkey2, }, ], }, { path: 'subkey3', ruleSet: ['required'], elementId: 'subkey3ElementId', }, ], dependantPaths: ['disableAllSubkey2Rule'], }, { path: 'listChild', ruleSet: [ { rule: 'required', customMessage: 'This list should not be empty' }, { rule: 'listSize', greaterThan: 2 }, ], elementId: 'listErrorFocusElement', }, { path: 'bottomElement1', ruleSet: ['required'] }, { path: 'bottomElement2', ruleSet: [{ rule: 'length', greaterThan: 3, applyToNulls: true }] }, { path: 'subComponentElement1', ruleSet: ['required'] }, { path: 'subComponentElement2', ruleSet: ['required'] }, ];
Rules Array Parameters
path (string) See Path API
Path of the value on formData to run the rule.
listPath (string) See Path API
Path of the values of a list on formData to run the rules on each elements of the list.
ruleSet (array) See Rule API
Rules to be applied to the value on path (Can be string or rule object).
elementId (string)
Custom elementId to focus after submit (path is used if empty).
listElementId (string)
Custom listElementId prefix to focus to elements with validation errors after submit (listPath is used if empty).
dependantPaths (array)
Array of paths that should trigger running the validation when there is a change on those paths.
disableFocusAfterSubmit (boolean)
Disable searching for element with given path to focus after submit if there is a validation error.
subRules (array)
Rules to be applied to the subpaths of the given list (can only be used with listPath).