MCPcopy Create free account
hub / github.com/formkit/formkit / reboot

Function reboot

packages/validation/src/validation.ts:204–228  ·  view source on GitHub ↗

* 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
    )

Source from the content-addressed store, hash-verified

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)

Callers 1

createValidationPluginFunction · 0.85

Calls 6

eqFunction · 0.90
cloneAnyFunction · 0.90
removeListenersFunction · 0.90
parseRulesFunction · 0.85
validateFunction · 0.85
removeMessageFunction · 0.70

Tested by

no test coverage detected