* Sets the internal value of the node. * * @param node - A FormKitNode | FormKitNode * @param context - A FormKitContext | FormKitContext * @param value - A input value to the node * @param async - If its an async call * * @returns `Promise ` * * @internal
( node: FormKitNode, context: FormKitContext, value: unknown, async = true )
| 1876 | * @internal |
| 1877 | */ |
| 1878 | function input( |
| 1879 | node: FormKitNode, |
| 1880 | context: FormKitContext, |
| 1881 | value: unknown, |
| 1882 | async = true |
| 1883 | ): Promise<unknown> { |
| 1884 | context._value = validateInput(node, node.hook.input.dispatch(value)) |
| 1885 | node.emit('input', context._value) |
| 1886 | if ( |
| 1887 | node.isCreated && |
| 1888 | node.type === 'input' && |
| 1889 | eq(context._value, context.value) && |
| 1890 | !node.props.mergeStrategy |
| 1891 | ) { |
| 1892 | node.emit('commitRaw', context.value) |
| 1893 | // Perform an early return if the value hasn't changed during this input. |
| 1894 | return context.settled |
| 1895 | } |
| 1896 | if (context.isSettled) node.disturb() |
| 1897 | if (async) { |
| 1898 | if (context._tmo) clearTimeout(context._tmo) |
| 1899 | context._tmo = setTimeout( |
| 1900 | commit, |
| 1901 | node.props.delay, |
| 1902 | node, |
| 1903 | context |
| 1904 | ) as unknown as number |
| 1905 | } else { |
| 1906 | commit(node, context) |
| 1907 | } |
| 1908 | return context.settled |
| 1909 | } |
| 1910 | |
| 1911 | /** |
| 1912 | * Validate that the current input is allowed. |
no test coverage detected