ui icon indicating copy to clipboard operation
ui copied to clipboard

[UFormGroup] How to Revalidate UFormGroup After Manually Setting v-model

Open hamonCordova opened this issue 1 year ago • 3 comments

Description

I'm using UFormGroup in my project and have a scenario where I need to invalidate a field and then manually set the v-model value without any user action. I have a component that sets the value of an input field, which can either be entered by the user or automatically selected. After manually setting the value, I want to trigger validation for the UFormGroup to reflect the new state.

How can I revalidate the UFormGroup programmatically after updating the v-model?

Expected Behavior:

Revalidate UFormGroup after invalidating the field and manually setting v-model.

Actual Behavior:

Validation does not trigger automatically after updating v-model programmatically.

Steps to Reproduce:

Invalidate a field in UFormGroup. Manually set v-model for that field. Observe that validation doesn't trigger.

hamonCordova avatar Aug 09 '24 20:08 hamonCordova

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Sep 09 '24 01:09 github-actions[bot]

Yeah I am interested in this too. I tested every :validate-on option on the UForm. Seems like the component needs to emit something to trigger the UFormGroup revalidation.

I have the UFormSelectMenu inside a custom component with a custom "clear" button. And the validation never triggers when the v-model is changed by the clear.

A best practice to manual trigger validation on UFormGroup would be helpful

schillerenrico avatar Sep 27 '24 01:09 schillerenrico

@hamonCordova I found something for us: https://stackblitz.com/edit/nuxt-ui-wnn5yk?file=components%2FCustomFileInput.vue

const { emitFormChange, emitFormBlur } = useFormGroup();

calling these methods trigger revalidation

schillerenrico avatar Sep 27 '24 02:09 schillerenrico

@hamonCordova I found something for us: https://stackblitz.com/edit/nuxt-ui-wnn5yk?file=components%2FCustomFileInput.vue

const { emitFormChange, emitFormBlur } = useFormGroup();

calling these methods trigger revalidation

@schillerenrico link you provided still error doesn't go away. Do you have other solution

ekta-7span avatar Nov 05 '24 23:11 ekta-7span

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Dec 06 '24 02:12 github-actions[bot]

The validation can be triggered from the Form component (using form.validate({ name: 'myinput' })) or using const { emitFormChange, emitFormBlur } = useFormGroup(); like @schillerenrico suggested.

romhml avatar May 23 '25 16:05 romhml