99import { CalendarDate , ModeType } from './Calendar'
1010import { LocalState } from './DatePickerModalContent'
1111import TextInputWithMask from '../TextInputMask'
12- import { useTheme } from 'react-native-paper'
12+ import { Text , useTheme } from 'react-native-paper'
1313
1414function CalendarEdit ( {
1515 mode,
@@ -129,6 +129,7 @@ function CalendarInputPure(
129129 ref : any
130130) {
131131 const theme = useTheme ( )
132+ const [ error , setError ] = React . useState ( false )
132133 const formatter = React . useMemo ( ( ) => {
133134 return new Intl . DateTimeFormat ( locale , {
134135 month : '2-digit' ,
@@ -155,26 +156,46 @@ function CalendarInputPure(
155156 const day = Number ( date . slice ( dayIndex , dayIndex + 2 ) )
156157 const year = Number ( date . slice ( yearIndex , yearIndex + 4 ) )
157158 const month = Number ( date . slice ( monthIndex , monthIndex + 2 ) )
158- if ( isEndDate ) {
159- onChange ( new Date ( year , month - 1 , day , 23 , 59 , 59 ) )
159+ if ( ! Number . isNaN ( day ) && ! Number . isNaN ( year ) && ! Number . isNaN ( month ) ) {
160+ setError ( false )
161+ if ( isEndDate ) {
162+ onChange ( new Date ( year , month - 1 , day , 23 , 59 , 59 ) )
163+ } else {
164+ onChange ( new Date ( year , month - 1 , day ) )
165+ }
160166 } else {
161- onChange ( new Date ( year , month - 1 , day ) )
167+ setError ( true )
162168 }
163169 }
164170 return (
165- < TextInputWithMask
166- ref = { ref }
167- value = { formattedValue }
168- style = { styles . input }
169- label = { `${ label } (${ inputFormat } )` }
170- keyboardType = { 'number-pad' }
171- placeholder = { inputFormat }
172- mask = { inputFormat }
173- onChangeText = { onChangeText }
174- returnKeyType = { returnKeyType }
175- onSubmitEditing = { onSubmitEditing }
176- keyboardAppearance = { theme . dark ? 'dark' : 'default' }
177- />
171+ < View style = { styles . inputContainer } >
172+ < TextInputWithMask
173+ ref = { ref }
174+ value = { formattedValue }
175+ style = { styles . input }
176+ label = { `${ label } (${ inputFormat } )` }
177+ keyboardType = { 'number-pad' }
178+ placeholder = { inputFormat }
179+ mask = { inputFormat }
180+ onChangeText = { onChangeText }
181+ returnKeyType = { returnKeyType }
182+ onSubmitEditing = { onSubmitEditing }
183+ keyboardAppearance = { theme . dark ? 'dark' : 'default' }
184+ />
185+ { error && (
186+ < Text
187+ style = { [
188+ {
189+ color : theme . colors . error ,
190+ } ,
191+ theme . fonts . medium ,
192+ styles . errorText ,
193+ ] }
194+ >
195+ { inputFormat }
196+ </ Text >
197+ ) }
198+ </ View >
178199 )
179200}
180201
@@ -183,8 +204,13 @@ const CalendarInput = React.forwardRef(CalendarInputPure)
183204const styles = StyleSheet . create ( {
184205 root : { padding : 12 } ,
185206 inner : { flexDirection : 'row' } ,
207+ inputContainer : { flex : 1 } ,
186208 input : { flex : 1 } ,
187209 separator : { width : 12 } ,
210+ errorText : {
211+ textAlign : 'right' ,
212+ marginTop : 12 ,
213+ } ,
188214} )
189215
190216export default React . memo ( CalendarEdit )
0 commit comments