Validation
Solid Formly give you a core rules or customize your own for validation a form 💯.
import { IField, getValues } from "solid-formly";
async function notEqual(): boolean {
const values = await getValues(form_name);
if (values.firstname === values.lastname) {
return false;
}
return true;
}
async function customRule2(): boolean {
const values = await getValues(form_name);
....
}
const fields: IField[] = [
{
type: "input",
name: "firstname",
attributes: {
id: "firstname"
},
},
{
type: "input",
name: "lastname",
attributes: {
id: "lastname"
},
rules: [notEqual, customRule2],
messages: {
// Custom message error
// property name must equal to function name.
notEqual: "Last name must not equal to First name",
customRule2: "foo bar"
}
}
];
In case you need to use file rules, must to add a file attribute to object's field with list rules, ex: