vee-validate icon indicating copy to clipboard operation
vee-validate copied to clipboard

Add `syncVModel` to `defineField`

Open BenJackGill opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

The useFeild composable has a convenient syncVModel option which is missing from defineField.

Many times I do not want to create a seperate component and instead just use defineField which is exported from useForm. The problem is that defineField doesn't have the syncVModel option so I cannot sync my own refs, such as the new definemodel which is very useful.

This issue was also brought up on StackOverflow, with more detailed code example: https://stackoverflow.com/questions/78657896/how-to-use-definemodel-with-vee-validate

Describe the solution you'd like

Add syncVModel option to defineField.

Describe alternatives you've considered

We can use a watchEffect instead, but that quickly becomes verbose because we need one per field.

watch(myRef, () => {
  veeValidateValueRefFromDefineField.value = myRef.value;
});

BenJackGill avatar Jun 28 '24 12:06 BenJackGill

Might be doable if you explicitly provide a model name/prop so it knows which events to emit. Since defineField is meant to be used multiple times within a component so it cannot default to modelValue like useField.

I don't see this on the roadmap anytime soon, but I will mark it as an enhancement.

logaretm avatar Jul 18 '24 22:07 logaretm