logaretm / vee-validate

✅ Painless Vue forms
https://vee-validate.logaretm.com/v4
MIT License
10.74k stars 1.26k forks source link

Add `syncVModel` to `defineField` #4797

Open BenJackGill opened 2 months ago

BenJackGill commented 2 months ago

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;
});
logaretm commented 1 month ago

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.