forms
forms copied to clipboard
fields.number() doesn't enforce number.
When I use fields.number(), it validates even if the field is not a number.
import forms, { fields, validators } from 'forms';
const nestedForm = forms.create({
age: fields.number({ required: validators.required('age') }),
});
const handlers = {
success(form) {
console.log('success');
},
other(form) {
console.log('fail');
},
};
nestedForm.handle({ age: 'this is a text' }, handlers);
// console prints "success"
Thanks for the report! Currently, the field doesn't come with implicit validators - it has a "parse" method which converts its value to a number, but you're expected to add the digits or integer validator yourself. fields.number more dictates the input "type" attribute, than validation.