Types and helpers, handling forms and their data.
Execute the following command from your project folder, where your package.json
file is stored:
npm install --save @egomobile/forms
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);
The module makes use of:
The API documentation can be found here.