No more form validations, with valid-me-react you can validate groups of items, independently of which form they belong to.
import ReactDOM from 'react-dom';
import {ValidMe,forceValidation,clearAllValidationErrors,phoneTypesEnum} from 'valid-me-react';
let doHi = () => {
let areThereErrors = forceValidation(undefined, undefined, 'hi'); //validate elements belonging to group hi
console.log(areThereErrors);
if (!areThereErrors){
clearAllValidationErrors();
}
}
let handleChange = (event) => {
console.log(event.target.value);
}
ReactDOM.render((
<div>
<div>
<ValidMe validmefor="numeric" group="hi">
<input type='text' onChange={handleChange}/>
</ValidMe>
</div>
<button data-group="hi" onClick={doHi}> //The library will add/remove a class called "disable" to elements of the group
Hi
</button>
</div>
), document.getElementById('app'));
numeric
text
text@alphanumeric
email
url
imageUrl
phoneNumber
*(need to be passed in validmefor attribute)
The styles available in the live-sample are on the sample-styles.css file
<ValidMe validmefor="required&condition" condition={function(value){})} >
<ValidMe validmefor="condition&text@1-5" condition={function(value){})} >
window.validMeReact.validMeManager.VALIDATION.CountryCode = 'US';
const phoneTypesSupported = `${phoneTypesEnum.MOBILE}-${phoneTypesEnum.FIXED_LINE}-${phoneTypesEnum.FIXED_LINE_OR_MOBILE}-${phoneTypesEnum.PERSONAL_NUMBER}-${phoneTypesEnum.VOIP}-${phoneTypesEnum.TOLL_FREE}`
<ValidMe validmefor={`phoneNumber@${phoneTypesSupported}`} >
<ValidMe group=firstGroupt&secondGroup validmefor="numeric" >
validmemessage
validmefor
validmecondition
validmeconditionmessage
validmenocolor
validmeerror
validmesuccess