0.7.1 • Published 2 years ago

@egomobile/forms v0.7.1

Weekly downloads
-
License
LGPL-3.0
Repository
github
Last release
2 years ago

npm last build PRs Welcome

@egomobile/forms

Types and helpers, handling forms and their data.

Install

Execute the following command from your project folder, where your package.json file is stored:

npm install --save @egomobile/forms

Usage

import { compileFormValidator, IForm } from "../src";

const form: IForm = {
  version: "1",
  components: [
    {
      class: "ETextField",
      name: "lastname",
      props: {
        label: "Last name",
      },
    },
    {
      class: "ETextField",
      name: "firstname",
      props: {
        label: "First name",
      },
    },
  ],
  schema: {
    format: "ajv",
    config: {
      type: "object",
      required: ["lastname", "firstname"],
      properties: {
        firstname: {
          type: "string",
        },
        lastname: {
          type: "string",
        },
      },
    },
  },
};

async function main() {
  const validate = compileFormValidator(form);

  // should return 1 error
  // because `firstname` has no value
  const validationResult = validate({
    lastname: "Doe",
  });

  console.log(validationResult);
}

main().catch(console.error);

Credits

The module makes use of:

Documentation

The API documentation can be found here.