'How to set value of datepicker in react native formik?
I'm trying to use react-native-datepicker in a Formik form.
I Have
<Formik
initialValues={inits}
validationSchema={() =>
yup.object({
username: yup
.string()
.nullable()
.required("Kamu belum memasukan Username"),
nama: yup
.string()
.nullable()
.required("Kamu belum memasukan Nama Lengkap"),
nik: yup
.string()
.nullable()
.required("Kamu belum memasukan NIK"),
no_telp: yup
.string()
.nullable()
.required("Kamu belum memasukan Nomor Telphone"),
email: yup
.string()
.nullable()
.required("Kamu belum memasukan Email"),
alamat: yup
.string()
.nullable()
.required("Kamu belum memasukan Alamat"),
})
}
enableReinitialize={true}
onSubmit={(values) => {
console.log(values);
}}
>
{({
handleChange,
handleSubmit,
values,
errors,
setFieldTouched,
touched,
}) => (
<View>
<InputText
name="username"
label="Username"
placeholder="Username"
// keyboardType="numeric"
onChangeText={handleChange("username")}
onBlur={() => setFieldTouched("username")}
value={values.username}
errors={errors}
touched={touched}
/>
<InputText
name="nama"
label="Nama Lengkap"
placeholder="Nama Lengkap"
// keyboardType="numeric"
onChangeText={handleChange("nama")}
onBlur={() => setFieldTouched("nama")}
value={values.nama}
errors={errors}
touched={touched}
/>
<InputText
name="nik"
label="NIK"
placeholder="Nomor Induk Keluarga"
keyboardType="numeric"
onChangeText={handleChange("nik")}
onBlur={() => setFieldTouched("nik")}
value={values.nik}
errors={errors}
touched={touched}
/>
<View>
<InputText
name="tgllahir"
label="Tanggal Lahir"
placeholder="test"
onChangeText={moment(date).format("DD/MM/YYYY")}
value={moment(date).format("DD/MM/YYYY")}
errors={errors}
touched={touched}
/>
<TouchableOpacity
style={style.formIcon}
onPress={() => setOpen(true)}
>
<Image source={calendar} />
<DatePicker
modal
mode="date"
open={open}
date={date}
onConfirm={(date) => {
setOpen(false);
setDate(date);
}}
onCancel={() => {
setOpen(false);
}}
/>
</TouchableOpacity>
</View>
<InputText
name="no_telp"
label="Telphone"
placeholder="Telphone"
keyboardType="numeric"
onChangeText={handleChange("no_telp")}
onBlur={() => setFieldTouched("no_telp")}
value={values.no_telp}
errors={errors}
touched={touched}
/>
<InputText
name="email"
label="Email"
placeholder="Email"
onChangeText={handleChange("email")}
onBlur={() => setFieldTouched("email")}
value={values.email}
errors={errors}
touched={touched}
/>
<InputText
name="alamat"
label="Alamat"
placeholder="Alamat"
onChangeText={handleChange("alamat")}
onBlur={() => setFieldTouched("alamat")}
value={values.alamat}
errors={errors}
touched={touched}
/>
<Button
title="Buat Akun"
variant="primary"
size="lg"
width="100%"
loading={loading_btn}
onPress={handleSubmit}
/>
</View>
)}
</Formik>
I want to take the value of datepicker item into the textinput value, but i don understand to make it. I set the value of text input with moment package and then call (date) , to call the date of datepicker, but couldnt find the value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

