GithubHelp home page GithubHelp logo

jcoreio / redux-form-numeric-field Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 4.47 MB

a customized redux-form Field for entering numbers

License: MIT License

JavaScript 7.61% TypeScript 92.39%
redux-form formatted-input numeric-input input-validation form-validation

redux-form-numeric-field's Introduction

redux-form-numeric-field

Build Status Coverage Status semantic-release Commitizen friendly npm version

A customized redux-form Field for entering numbers. It isn't contrary; it won't stop you from typing, pasting, or cutting any characters, though it will produce a "must be a number" validation error immediately if the current input is invalid. When it loses focus it will normalize its value to a number, if valid; otherwise it will trim its value but leave it as a string.

Usage

npm install --save redux-form-numeric-field
const { NumericField } = require('redux-form-numeric-field')

or

const { NumericField } = require('redux-form-numeric-field/immutable')

Example

The following field will normalize its value to a number when it loses focus (unless the text is not a valid number, in which case it will just trim the text when it loses focus).

<NumericField name="value" component={YourInputComponent} />

API

NumericField

Has the same API as redux-form's Field, but normalizes its value to a number when it loses focus (unless the text is not a valid number, in which case it will just trim the text when it loses focus).

normalizeNumber?: (value: ?(string | number)) => ?(string | number)

Allows you to override the default implementation which is called on blur. If value is a number or correctly-formatted string, return a number; otherwise, return a string or null.

normalizeOnBlur?: (value: ?(string | number)) => ?(string | number)

If you provide this, it will be called with the output of normalizeNumber when the field loses focus.

validate?: Validator | Array<Validator>

Unlike a normal Field, NumericField will call your validators with the normalized value from normalizeNumber. If its value is an invalid number but not whitespace, it will produce a "must be a number" validation error without calling your own validators.

redux-form-numeric-field's People

Contributors

greenkeeper[bot] avatar jedwards1211 avatar renovate-bot avatar renovate[bot] avatar

Watchers

 avatar  avatar  avatar  avatar

redux-form-numeric-field's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.