Skip to content

v0.2.2

Latest
Compare
Choose a tag to compare
@domutala domutala released this 16 Jul 11:42
· 4 commits to main since this release

What's new in version 0.2.2 of formons?

Validatorsbecome arrays

To be able to execute the validators by priority, they have been transformed into array. Validator priority based on schema order and order of arrival in Schema.validators.

export interface SchemaInterface {
  /** formons-shema="key" */
  el?: Element;
  [key: string]: any;
}

export interface Schema {
  // --

  /**
   * validation functions are called before submitting form and after `Schema.onBeforeSubmit`.
   * They can also be called directly with the `Model.validate` function.
   *
   * The aim is to fill in `Model.isFormValid` and update `Schema.errors`.
   *
   * Validator priority based on schema order and order of arrival in `Schema.validators`.
   * */
  validators: Array<SchemaValidator>;

  // ---
}

Events 🆕

Execute functions at different stages of your form.

export interface Schema {
  // ---

  events: SchemaEvents;

  // ---
}

export interface SchemaEvents {
  /** After creating the model */
  onModelCreated?: (key: string, model: Model) => Model | Promise<Model>;

  /** This function is called after the `Model.mount` function has been called. */
  onMounted?: (key: string, model: Model) => Model | Promise<Model>;

  /** this function is called before the form is submitted */
  onBeforeSubmit?: (key: string, model: Model) => Model | Promise<Model>;

  /** custom event like `onSave` for example  */
  [funcName: string]:
    | ((key: string, model: Model) => Model | Promise<Model>)
    | undefined;
}

@domutala