Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

egomobile/node-forms

Repository files navigation

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.