@modular-forms/qwik
Version:
The modular and type-safe form library for Qwik
38 lines (37 loc) • 1.11 kB
JavaScript
import { useStore } from '@builder.io/qwik';
import { getInitialStores } from '../utils';
/**
* Creates and returns the store of the form.
*
* TODO: Add initialValues option beside loader
*
* @param options The form options.
*
* @returns The reactive store.
*/
export function useFormStore({ validate, validateOn = 'submit', revalidateOn = 'input', ...options }) {
return useStore(() => {
const [fields, fieldArrays] = getInitialStores(options);
return {
internal: {
fields,
fieldArrays,
fieldArrayPaths: options.fieldArrays,
validate,
validators: [],
validateOn,
revalidateOn,
},
// FIXME: Set state based on `action`
element: undefined,
submitCount: 0,
submitting: false,
submitted: false,
validating: false,
touched: false,
dirty: false,
invalid: false,
response: options.action?.value?.response || {},
};
});
}