@@ -9,57 +9,64 @@ import styles from './styles';
99
1010const FormInput = ( props ) => {
1111 const {
12- input,
1312 containerStyle,
1413 inputContainerStyle,
15- meta : { error, touched } ,
1614 inlineImage,
15+ name,
16+ handleChange,
17+ handleBlur,
18+ errors,
19+ touched,
20+ value,
1721 ...inputProps
1822 } = props ;
1923
24+ const hasError = touched [ name ] && errors [ name ] ;
25+
2026 const renderError = ( ) => {
21- if ( touched && error ) {
22- return < DefaultText > { error } </ DefaultText > ;
27+ if ( hasError ) {
28+ return < DefaultText > { errors [ name ] } </ DefaultText > ;
2329 }
2430 return null ;
2531 } ;
2632
33+
2734 return (
2835 < View style = { [ styles . container , containerStyle ] } >
2936 < View
3037 style = { [
3138 styles . inputContainer ,
3239 inputContainerStyle ,
33- ( error && touched ) ? styles . errorInput : null ,
40+ ( hasError ) ? styles . errorInput : null ,
3441 ] }
3542 >
3643 < DefaultInput
3744 style = { styles . input }
3845 { ...inputProps }
39- onChangeText = { input . onChange }
40- onBlur = { input . onBlur }
41- onFocus = { input . onFocus }
42- value = { input . value }
46+ onChangeText = { handleChange ( name ) }
47+ onBlur = { handleBlur ( name ) }
48+ value = { inputProps . value }
4349 />
4450 </ View >
4551 < View style = { styles . errorContainer } >
46- {
47- renderError ( )
48- }
52+ { renderError ( ) }
4953 </ View >
5054 </ View >
5155 ) ;
5256} ;
5357
5458FormInput . propTypes = {
59+ ...DefaultInput . propTypes ,
5560 input : PropTypes . object ,
5661 containerStyle : PropTypes . any ,
57- meta : PropTypes . shape ( {
58- touched : PropTypes . bool ,
59- error : PropTypes . any ,
60- } ) ,
6162 inlineImage : PropTypes . any ,
6263 inputContainerStyle : PropTypes . any ,
64+ name : PropTypes . string . isRequired ,
65+ handleChange : PropTypes . func ,
66+ handleBlur : PropTypes . func ,
67+ errors : PropTypes . object ,
68+ touched : PropTypes . object ,
69+ value : DefaultInput . propTypes . value ,
6370} ;
6471
6572export default FormInput ;
0 commit comments