Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fields.number() doesn't enforce number. #166

Open
yaru22 opened this issue Aug 7, 2015 · 1 comment
Open

fields.number() doesn't enforce number. #166

yaru22 opened this issue Aug 7, 2015 · 1 comment

Comments

@yaru22
Copy link

yaru22 commented Aug 7, 2015

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"
@ljharb
Copy link
Collaborator

ljharb commented Aug 8, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants