fields.number() doesn't enforce number.

Open Beginner friendly
#166 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript, node.js
Domain
backend

Research direction

Start by reproducing the supplied fields.number() example with the string value, then inspect the fields.number() implementation and its validation path. Done means non-numeric input is rejected while valid numbers retain their current behavior; add or update a regression test if the repository’s existing test structure identifies one.

Written by the indexing model from the issue text.

Description

Feature Requests Needs More Info

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"
Dominant language
JavaScript
Stars
1k
Forks
161
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from caolan/forms

All issues in caolan/forms

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.