Closed abhiburk closed 2 months ago
Ok I had to take ref on the input field
const pin = ref(formValues.pin);
<PinInputInput :ref="pin" class="rounded-md border h-12 w-12" :index="index" />
and then on submit
pin.value = []
closeDialog();
resetForm();
Based on PIN Input Form example https://www.shadcn-vue.com/docs/components/pin-input#form
You can use useForm
, initialValues
like
const { handleSubmit, setFieldValue } = useForm({
validationSchema: formSchema,
initialValues: {
pin: [],
},
})
Check this Stackblitz
I am using Dialog here and inside that I am using PinInput in one of your threads, you recommend using Form for dialog feature. So I am using Form
and not useForm
.
Also I noticed there is issue in the form example, may be some syntax error
<PinInput
id="pin-input"
v-model="value!" <--- here
placeholder="○"
class="flex gap-2 items-center mt-1"
otp <--- this
type="number"
:name="componentField.name"
@complete="handleComplete"
@update:model-value="(arrStr) => {
setFieldValue('pin', arrStr.filter(Boolean))
}"
>
Sry that was a mistake using v-model
in that example
You need to use :model-value
instead
Also I'll share a Stackblitz with Dialog + PIN Input example here
Thank You @sadeghbarati. You are awesome :-)
I am following the https://www.shadcn-vue.com/docs/components/pin-input.html where the resetForm is not working on the PinInput component. It does reset the form but I think the input values are still visible in 4 OTP fields. Even formValues seems to be not working as expected.