You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportdefaultfunction(){return(<Validationdata={data}schema={schema}style={{color: 'maroon',fontWeight: 'bold'}}className="custom CN">
// ... form
</Validation>);}
pass error codes dictionary
consterrorCodes={TOO_SHORT: 'password is too short'}exportdefaultfunction(){return(<Validationdata={data}schema={schema}errorCodes={errorCodes}>
// ... form
</Validation>);}
russian dictionary
default locale is english but you can import russian dictionary from package
import{RU_ERROR_CODES}from'react-livr-validation'
write your own validation component
// @flowimportReact,{Component}from'react'import{ValidationComponent}from'react-livr-validation'importgetfrom'lodash/get'importnoopfrom'lodash/noop'importcomposefrom'ramda/src/compose'importstyledfrom'styled-components'typeDataChunk={name: string,value: any}typeState={touched: boolean}typeProps={// will be passed by HOCsetData: (data: DataChunk)=>void,getError: (name: string)=> ?string,getErrors: ()=>Object,className: string,// for the error blockstyle: Object// for the error blockerrorCodes: Object,name: string,field: string}classNestedErrorextendsComponent{props: Props;isTouched(){const{children}=this.props;returnget(children,'props.value')}state: State={touched: this.isTouched()}setTouched(){this.setState({touched: true})}cloneElement(){const{children}=this.props;constonBlur=get(children,'props.onBlur',noop);returnReact.cloneElement(children,{onBlur: compose(this.setTouched,onBlur)})}render(){const{touched}=this.state;const{
children,
field,
name,
getError,
errorCodes,
style,
className
}=this.props;consterrors=getErrors();consterror=get(errors,`${field}`.${name});return(<div>{touched ? children : this.cloneElement()}{error&&<ErrorclassName={className}style={style}>{errorCodes[error]||error}</Error}</div>);}}constError=styled.div` color: red;`;exportdefaultValidationComponent(NestedError)
Classes
Validation
prop
type
default value
data
object
{}
schema
object
{}
rules
object
{}
aliasedRules
object
{}
className
string
''
style
object
{}
errorCodes
object
{}
ValidationInput
prop
type
default value
name
string
''
validateOnEvents
array
['change', 'blur', 'keyUp']
About
validation component for react with LIVR as validation engine