forms icon indicating copy to clipboard operation
forms copied to clipboard

fields.number() doesn't enforce number.

Open yaru22 opened this issue 10 years ago • 1 comments

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"

yaru22 avatar Aug 07 '15 18:08 yaru22

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.

ljharb avatar Aug 08 '15 06:08 ljharb