Configuration reference
Felte's createForm function accepts a configuration object with the following properties:
- onSubmit: (See Submitting) a function that receives as a first argument the submitted data, and as a second argument a
contextobject with the following properties:- form: the native HTML form element.
- event: the event that'd be dispatched to an event handler when submitting a form.
- controls: the form's native HTML controls.
- config: the current configuration of the form.
- validate: a validation function (or array of functions) that receives the data to validate and returns an
errorsobject, orundefinedif the data is valid. The validation functions may be asynchronous. See Validation. - warn: a validation function (or array of functions) that receives the data to validate and returns an object with the same shape as
data, but with warning messages orundefinedas values. It can be an array of functions whose validation errors will be merged. See Validation. - transform: a transformation function (or array of functions) that receives the data coming from your form and returns a
dataobject. See Transformations. - onSuccess: a function that receives anything returned from the
onSubmitfunction, or theResponseobject fromfetchif noonSubmitfunction is provided. Useful for reacting when a form is succesfully submitted. - onError: a function that receives any unhandled errors thrown in the
onSubmitfunction, or an instance ofFelteSubmitErrorif noonSubmithandler is provided. Useful for handling server errors. It can be asynchronous. - extend: an extender or array of extenders. Currently these are either validators or reporters. Note that extenders may add/change this same configuration object. Check their documentation when adding one.
- debounced: (See Validation) an object that contains the validations you'd like to be debounced (executed a certain amount of time after the user stops interacting with your form). It contain the following properties:
- validate: the same as the
validatefunction described above. - warn: the same as the
warnfunction described above. - timeout: time in milliseconds to wait after the user stops interacting with your form before running the validation functions. Defaults to 300.
- validateTimeout: time in milliseconds that overrides the value of
timeoutfor yourvalidatefunctions. - warnTimeout: time in milliseconds that overrides the value of
timeoutfor yourwarnfunctions.
- validate: the same as the
Every property is optional.