Beautiful functional masked input-element for react. Thanks to https://www.npmjs.com/package/react-maskedinput
For all mask
-options, see: https://github.com/insin/inputmask-core#pattern
How to use:
const ReactDOM = MaskedInput = ; let props = phone: ''; const handleChange = { propsphone = etargetvalue; ;}; const renderTextarea = { ReactDOM;}; ;
About the css
You need the right css in order to make use of itsa-react-maskedinput
. There are 2 options:
- You can use the css-files inside the
css
-folder. - You can use:
Component = require("itsa-react-maskedinput/lib/component-styled.jsx");
and build your project withwebpack
. This is needed, because you need the right plugin to handle a requirement of thescss
-file.
Sophisticated forms
In adjunction with other itsa-react-components
, you can build very sophisticated forms:
example sophisticated form with validation
This example has the following code:
css
html
app.js
"use strict"; ;;; ;;;; const React = ReactDOM = Input = MaskedInput = Checkbox = Textarea = REG_EXP_PHONE = /^\(\d{0,3}\) \d{0,3}\-\d{0,4}$/; /******************************************************* * Custom form-Component *******************************************************/const MyForm = React; /******************************************************* * Event-hanldlers *******************************************************/const handleChangeName = { ;}; const handleChangeEmail = { ;}; const handleChangePassword = { ;}; const handleChangePhone = { ;}; const handleChangeComment = { ;}; const handleSubmit = { const formValid = eformValid form = etarget; formValid || form;}; const handleTermsAccepted = { ;}; /******************************************************* * Validation *******************************************************/const validate = { let valid; if !validators return true; validators; return !!valid;}; const validatorsDefinition = { return !!val } { return val; // comes from itsa/lib/string } { return val && vallength>=5; } { return REG_EXP_PHONE || !val; } { return !!val; }; const validateProps = { props;}; /******************************************************* * props *******************************************************/let props = name: '' email: '' password: '' comment: '' phone: '' termsAccepted: false onChangeName: handleChangeName onChangeEmail: handleChangeEmail onChangePassword: handleChangePassword onChangePhone: handleChangePhone onChangeComment: handleChangeComment onSubmit: handleSubmit onTermsAccepted: handleTermsAccepted validated: {} validators: email: "required" "email" name: "required" phone: "required" "phone" termsAccepted: "checked" password: "required" "password" ; const redefineProps = { if key==='termsAccepted' propstermsAccepted = !propstermsAccepted; else propskey = value; ; ;}; /******************************************************* * React render form *******************************************************/const renderForm = { ReactDOM;}; /******************************************************* * Initialization *******************************************************/;;
If you want to express your appreciation
Feel free to donate to one of these addresses; my thanks will be great :)
- Ether: 0xE096EBC2D19eaE7dA8745AA5D71d4830Ef3DF963
- Bitcoin: 37GgB6MrvuxyqkQnGjwxcn7vkcdont1Vmg