Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
redux-form-input-masks
Advanced tools
redux-form-input-masks
is a library that works with redux-form
to easily add masking to Field
s.
Redux is awesome and so are input masks: they help standardizing inputs and improves the UX of the application. redux-form
has support for input formatting, parseing and normalizing, but it can get pretty tricky to implement a mask with these functions. redux-form-input-masks
offer simple APIs to create these masks so you don't need to worry about it!
Also, the value of the Field
s in any application should be agnostic of how the Field
s themselves are presented to the user. For example, if there's a currency field in a form, it makes more sense to store the value as a number. Storing Field
values in a way that makes more sense for the application makes it easier to integrate form data with backend services and to create validations for it. With redux-form-input-masks
you can also choose how the value of a formatted Field
will be stored in the application's store.
redux-form-input-masks
returns objects implementing redux-form
's Value Lifecycle Hooks and also some Global Event Handlers to manage the caret position.
npm install --save redux-form-input-masks
or
yarn add redux-form-input-masks
redux-form
out of the box, you just need to install redux-form-input-masks
and you're good to go;redux-form-input-masks
works with basically all combinations of versions of react
, react-dom
, react-redux
, redux
and redux-form
;redux-form-input-masks
;material-ui
and redux-form-material-ui
's wrappers, for both v0-stable and v1-beta versions.Name | Description | API Reference | Demo |
---|---|---|---|
Number Mask | Ideal for currency, percentage or any other numeric input. Supports prefix, suffix, locale number formatting and even more options. You can also choose wether the value is stored as number or string . | createNumberMask | codesandbox.io |
Text Mask | Flexible string mask. Lets you specify the pattern, inputtable characters and much more. | createTextMask | codesandbox.io |
It's super simple to apply a mask using this library. You just need to import your mask creator from redux-form-input-masks
, specify the parameters and pass it to the Field
using spread attributes. Yep, it's that easy.
You can find several examples including demos on our documentation.
Here's a simple snippet that uses createNumberMask
and createTextMask
and applies them to Field
s:
import { createNumberMask, createTextMask } from 'redux-form-input-masks';
(...)
const currencyMask = createNumberMask({
prefix: 'US$ ',
suffix: ' per item',
decimalPlaces: 2,
locale: 'en-US',
})
const phoneMask = createTextMask({
pattern: '(999) 999-9999',
});
(...)
<Field
name="amount"
component="input"
type="tel"
{...currencyMask}
/>
<Field
name="phone"
component="input"
type="tel"
{...phoneMask}
/>
FAQs
Input masking with redux-form made easy
The npm package redux-form-input-masks receives a total of 4,783 weekly downloads. As such, redux-form-input-masks popularity was classified as popular.
We found that redux-form-input-masks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.