-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aggregated form validation #4181
Comments
The nested observers/forms idea was removed since I couldn't find a good justification for it, most single root forms can do the same thing as a nested form setup with minor changes. Having said that, I may not have encountered the use case to convince me of introducing it yet. However, there could be a place for a simpler abstraction. Like a I can probably start working on it for // FormGroup.vue
const fields = ref<FieldContext[]>([]);
provide('FormGroup', fields);
// You can build other stuff similar to this
const meta = computed(() => {
const valid = fields.value.every(f => f.meta.valid);
const dirty = fields.value.some(f => f.meta.dirty);
const touched = fields.value.some(f => f.meta.touched);
return { valid, dirty, touched };
});
// InputText.vue
const field = useField(...);
const group = inject('FormGroup');
if (group) {
group.push(field);
} |
Thanks a lot for your reply. I certainly would appreciate having this feature added. Our use case in some more detail (to perhaps help with the convincing :):
So, the formGroup would need to have a FormMeta state, aggregated from the contained forms in the same way as forms aggregate field meta states. Plus access to the contained forms, i.e. the values, validate and reset functions etc. In the meantime I will try to implement this using your suggestions, but instead of registering FieldContexts on the FormGroup, I will register the contained FormContexts. |
I may also have near exact use case that @okoell has.. thinking about how we will have a form with some top level fields but also I want to add one to many field-identical sub-forms with at least 10 different fields and their own validation rules. I'll study the workaround a bit but given my low experience with VeeValidate it isn't immediately obvious how it wires together. Thanks! |
Yep would really be helpful if we can do this. |
As somebody currently migrating a Vue 2 to Vue 3 multi-step wizard form with multiple sub-components... Having this feature would make my life much easier. Not sure how feasible the proposed workaround would be until then |
Yeah, we are also trying to migrate and everything went relatively smoothly so far. But not we are kinda stuck with this. Our use case is also something like sections with validation status for each of them like:
The workaround I see for now is to create custom Do you have any other idea or maybe there is some work already done on this @logaretm ? |
@logaretm I've done some testing, can be seen here: Basically what is missing here for me is the access to the |
Here is an example with modified version of vee-validate: |
Thanks for both of your contributions. I don't know about field groups since it can be user-land and I will continue the discussion there. For the expose one, I'm fine with it as long as we get the types corrected. |
Sure, I'll look into that later. Regarding the groups I aso think we could expand this behavior to composable too. In that case we could create something like |
We are in the process of migration a large Vue 2 application to Vue 3 - including the update from vee-validate v3 to v4.
The UI provides a list of forms for a (dynamic) list of model entities, all of the same type. It can be submitted when one or more of the forms have changes and are valid.
This requires an aggregated view of the single form validation states. In vee-validate v3 we implemented this with Nested Observers - i.e. we have a global ValidationObserver combining the state of the contained form ValidationObservers.
This is documented (if not recommended) in the v3 docs and works quite nicely.
In vee-validate v4 I don't see anything comparable supporting this use case.
Do you have any plans to introduce this later? Or ideas how to tackle the problem with the existing features?
The text was updated successfully, but these errors were encountered: