* Reboots the validation using new rules or declarations/intents. * @param newValidation - New validation declaration to use * @param newRules - New validation rules to use * @returns
(
newValidation: undefined | string | FormKitValidationIntent[],
newRules: FormKitValidationRules
)
| 202 | * @returns |
| 203 | */ |
| 204 | function reboot( |
| 205 | newValidation: undefined | string | FormKitValidationIntent[], |
| 206 | newRules: FormKitValidationRules |
| 207 | ) { |
| 208 | if ( |
| 209 | eq(Object.keys(propRules || {}), Object.keys(newRules || {})) && |
| 210 | eq(validation, newValidation) |
| 211 | ) |
| 212 | return |
| 213 | propRules = cloneAny(newRules) |
| 214 | validation = cloneAny(newValidation) |
| 215 | availableRules = { ...baseRules, ...propRules } |
| 216 | // Destroy all observers that may re-trigger validation on an old stack |
| 217 | // Clear existing message observers |
| 218 | node.props.parsedRules?.forEach((validation: FormKitValidation) => { |
| 219 | removeMessage(validation) |
| 220 | removeListeners(validation.observer.receipts) |
| 221 | validation.observer.kill() |
| 222 | }) |
| 223 | // Remove all existing messages before re-validating |
| 224 | node.store.filter(() => false, 'validation') |
| 225 | node.props.parsedRules = parseRules(newValidation, availableRules, node) |
| 226 | state.isPassing = true |
| 227 | validate(node, node.props.parsedRules, state) |
| 228 | } |
| 229 | |
| 230 | // Validate the field when this plugin is initialized |
| 231 | node.props.parsedRules = parseRules(validation, availableRules, node) |
no test coverage detected