Form Actions

The form actions can be used only on the form instance.


Validate the Form

The validate() action returns a promise.

The callback takes the Field Instance with its isValid prop, which is the validation state of the Form.

form.validate()
  .then(({ isValid }) => {
    ... // Use `isValid` to check the validation status
  });

The validation promise resolves the validated instance (Form or Field).

Validate Single Field

The validate(path) action get an optional field path in input and returns a promise.

The callback takes a boolean (isValid) with the validation state of the Field.

form.validate('email')
  .then(({ isValid }) => {
    ... // Use `isValid` to check the validation status
  });

The validation promise resolves the validated instance (Form or Field).

This is an alternative syntax to Actions - Validate a Field.

Validation Errors

The validate() method will not show errors by default.

If you need to show errors after a validation you do:

form.validate({ showErrors: true });

or on single field:

form.validate('email', { showErrors: true });

Re-Initialize all Fields

The init() method will re-init the form with empty or new values and all previous data will be discarded.

If you don't need to re-init the form fields and values, just use the update() method.

It works like passing the fields or values to the Form Constructor.

It accept the fields struct if using separated properties definition or fields values if using unified properties definition.


Re-init the form with empty values:

.init();

Use an object to Re-Init the form with new values (unified properties definition):

form.init({
  username: 'NewUsername',
  password: 'NewPassword',
});

Use the fields struct to Re-Init with empty fields (separated properties definition):

form.init([
  'members[]'
  ...
]);

then you can update the fields values normally using the update() method.

You can use the init() method if you need to add new fields too, for this purpose you have to provide the new complete fields struct or fields values or the missing fields will be lost.

results matching ""

    No results matching ""