|
|
@ -33,66 +33,46 @@ function IncreaseDecreaseButtons({ content }) { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
function AppFormField({ |
|
|
|
function RenderPluviometerInput({ |
|
|
|
name, |
|
|
|
width, |
|
|
|
increaseDecreaseButtons = false, |
|
|
|
...otherProps |
|
|
|
}) { |
|
|
|
const { |
|
|
|
values, |
|
|
|
setFieldTouched, |
|
|
|
setFieldValue, |
|
|
|
errors, |
|
|
|
touched, |
|
|
|
} = useFormikContext(); |
|
|
|
|
|
|
|
const [pluv, setPluv] = useState(0); |
|
|
|
|
|
|
|
console.log(values); |
|
|
|
console.log(pluv); |
|
|
|
otherProps, |
|
|
|
width, |
|
|
|
values, |
|
|
|
}) { |
|
|
|
console.log(name == "pluviometer"); |
|
|
|
const [fieldVal, setFieldVal] = useState(values[name]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
setFieldValue("pluviometer", Number(pluv), true); |
|
|
|
}, [pluv]); |
|
|
|
setFieldValue(name, fieldVal, true); |
|
|
|
}, [fieldVal]); |
|
|
|
|
|
|
|
const increase = () => { |
|
|
|
setPluv((Number(pluv) + 1).toString()); |
|
|
|
setFieldVal((Number(fieldVal) + 1).toString()); |
|
|
|
}; |
|
|
|
|
|
|
|
const decrease = () => { |
|
|
|
setPluv((Number(pluv) - 1).toString()); |
|
|
|
setFieldVal((Number(fieldVal) - 1).toString()); |
|
|
|
}; |
|
|
|
|
|
|
|
return ( |
|
|
|
<View> |
|
|
|
<View |
|
|
|
style={{ |
|
|
|
flex: 1, |
|
|
|
flexDirection: "row", |
|
|
|
paddingLeft: 16, |
|
|
|
paddingRight: increaseDecreaseButtons ? 0 : 16, |
|
|
|
}} |
|
|
|
> |
|
|
|
<View |
|
|
|
style={{ |
|
|
|
alignSelf: "stretch", |
|
|
|
flex: 1, |
|
|
|
}} |
|
|
|
> |
|
|
|
<View style={{flex: 1,alignSelf: "stretch"}}> |
|
|
|
<TextInput |
|
|
|
onBlur={() => setFieldTouched(name)} |
|
|
|
onChangeText={(val) => { |
|
|
|
setPluv(val); |
|
|
|
setFieldVal(val); |
|
|
|
}} |
|
|
|
width={width} |
|
|
|
value={pluv} |
|
|
|
{...otherProps} |
|
|
|
/> |
|
|
|
value={fieldVal.toString()} |
|
|
|
{...otherProps}/> |
|
|
|
</View> |
|
|
|
|
|
|
|
{increaseDecreaseButtons && ( |
|
|
|
<> |
|
|
|
<TouchableOpacity |
|
|
|
onPress={() => { |
|
|
|
increase(); |
|
|
@ -118,11 +98,53 @@ function AppFormField({ |
|
|
|
> |
|
|
|
<IncreaseDecreaseButtons content={"-"} /> |
|
|
|
</TouchableOpacity> |
|
|
|
</> |
|
|
|
</View> |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
function AppFormField({ |
|
|
|
name, |
|
|
|
width, |
|
|
|
increaseDecreaseButtons = false, |
|
|
|
...otherProps |
|
|
|
}) { |
|
|
|
const { |
|
|
|
values, |
|
|
|
setFieldTouched, |
|
|
|
setFieldValue, |
|
|
|
handleChange, |
|
|
|
errors, |
|
|
|
touched, |
|
|
|
} = useFormikContext(); |
|
|
|
|
|
|
|
return ( |
|
|
|
<View> |
|
|
|
<View |
|
|
|
style={{ |
|
|
|
paddingLeft: 16, |
|
|
|
paddingRight: increaseDecreaseButtons ? 0 : 16, |
|
|
|
}} |
|
|
|
> |
|
|
|
{name != "pluviometer" ? ( |
|
|
|
<TextInput |
|
|
|
onBlur={() => setFieldTouched(name)} |
|
|
|
onChangeText={handleChange(name)} |
|
|
|
width={width} |
|
|
|
{...otherProps} |
|
|
|
/> |
|
|
|
) : ( |
|
|
|
<RenderPluviometerInput |
|
|
|
name={name} |
|
|
|
setFieldTouched={setFieldTouched} |
|
|
|
setFieldValue={setFieldValue} |
|
|
|
otherProps={otherProps} |
|
|
|
width={width} |
|
|
|
values={values} |
|
|
|
/> |
|
|
|
)} |
|
|
|
</View> |
|
|
|
|
|
|
|
<View style={{ paddingLeft: 16 }}> |
|
|
|
<View style={{ paddingHorizontal: 16}}> |
|
|
|
<ErrorMessage error={errors[name]} visible={touched[name]} /> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|