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

Function clearState

packages/core/src/reset.ts:11–33  ·  view source on GitHub ↗

* Clear all state and error messages. * * @internal

(node: FormKitNode)

Source from the content-addressed store, hash-verified

9 * @internal
10 */
11function clearState(node: FormKitNode) {
12 const clear = (n: FormKitNode) => {
13 const hasValidationMessages = Object.values(n.store).some(
14 (message) => message.type === 'validation'
15 )
16 for (const key in n.store) {
17 const message = n.store[key]
18 if (
19 message.type === 'error' ||
20 (message.type === 'ui' && key === 'incomplete')
21 ) {
22 n.store.remove(key)
23 } else if (message.type === 'state') {
24 n.store.set({
25 ...message,
26 value: key === 'failing' ? hasValidationMessages : false,
27 })
28 }
29 }
30 }
31 clear(node)
32 node.walk(clear)
33}
34
35const missingResetValue = Symbol('missingResetValue')
36

Callers 1

resetFunction · 0.85

Calls 1

clearFunction · 0.85

Tested by

no test coverage detected