Custom Event Hooks
On Form Initialization
Define a hooks object with Event Hook functions and pass them to the Form Constructor (second argument) or to the Field Definition (first argument).
Defining hooks on Form
Available hooks on Form: onSubmit, onClear, onReset, onAdd, onDel.
Pass the
hooksobject to the Second Argument.
javascript
const hooks = {
onSubmit(form) {
console.log('-> onSubmit HOOK - isValid?', form.isValid);
},
};
new Form({ ... }, { hooks }); // <--- second argumentDefining hooks on Field
Available hooks on Field: onChange, onToggle, onFocus, onBlur, onDrop, onSubmit, onClear, onReset, onAdd, onDel, onKeyUp, onKeyDown.
Pass the
hooksobject to the First Argument in the field definitions (unified or separated).
Unified mode:
javascript
const fields = {
username: {
label: 'Username',
value: 'SteveJobs',
hooks: {
onBlur(field) {
console.log('-> onBlur HOOK', field.path);
},
},
},
};
new Form({ fields }, { ... });Separated mode:
javascript
const hooks = {
username: {
onBlur(field) {
console.log('-> onBlur HOOK - Field:', field.path);
},
},
};
new Form({ fields: ['username'], hooks });