-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Form: Request to expose functionality to code such as .reset()
, .validate()
, .submit()
, etc
#7046
Comments
Exp;
|
It would also be nice to be able to handle async validations that happen during submission nicely - something like the vee-validate Also the current mechanism seems to make it difficult to do things like initially validate on blur, but if there is an error, validate on change so the user can know when they have fixed the problem. |
I agree that this is more user friendly way to validate forms. I solved this problem temporarily like this. I hope there will be a better solution in the future version: // Validate on blur until field is touched, then validate on each update (eagerly)
const form = useTemplateRef<{ states: Record<string, FormFieldState | undefined> }>('form')
const validateOnValueUpdate = computed(() => {
const states = form.value?.states ?? {}
return Object.keys(states).filter((field) => states[field]?.touched ?? false)
}) <Form ref="form" :validate-on-value-update :validate-on-blur="true">...</Form> So, it is not difficult. The only tricky part is to access internal API of the form instance, that I would like to avoid. But of course it would be much better to have this option out of the box, e.g. be able to set |
Did anything like this get added with the new 4.3.0 update? Specifically, validation should not trigger while typing but should validate on blur. If an error appears, it should then validate on input so the error clears immediately while typing. This prevents premature validation distractions while typing and ensures errors resolve smoothly, improving the user experience. Previously I was using VeeValidate like that and it provided the best user experience. |
I somewhat disagree with this logic. Or, rather, I almost agree, but with one change. I think the better would be like this: Validation should not trigger while typing but should validate on blur. If validation of this field is performed at least once (so, the field's So, the change in the logic I suggest is to switch to "eager validation" not only on error, but also when there was no error, but user touched the field. This way the validation will not be premature, but at the same time if user toches the field again and changes the value from a valid to an invalid, the user will immideately see the feedback. I seen exactly this logic in many well-known admin panels of big companies and I think this is the most user-friendly way in most cases.
Answering this question: I don't think so. It was just an idea that most likely left unseen by someone who really could take this decision. Maybe it is worth to open a new issue for this. |
Describe the bug
Description
Currently, the
Form
component only exposes form state via thev-slot="$form"
, making it difficult to programmatically control forms from script code. Common operations like resetting, validating, or submitting forms require direct template access to$form
, which creates unnecessary coupling between template and logic.Related Issues and Discussions
This functionality has been requested in various forms across different issues. I'm creating this consolidated issue to track the core problem: the need for programmatic form control. Related issues and discussions:
While these issues approach the problem from different angles, they all stem from the same root cause: lack of programmatic access to form methods. Having a single solution that exposes a complete form instance API would resolve all these cases.
We need the ability to call form methods from script code for scenarios like:
Example Use Case
Proposed Solution
This is just a suggestion:
Benefits
Pull Request Link
No response
Reason for not contributing a PR
Other Reason
No response
Reproducer
N/A
Environment
Node
Vue version
3.5.13
PrimeVue version
4.2.5
Node version
No response
Browser(s)
No response
Steps to reproduce the behavior
See above
Expected behavior
See above
The text was updated successfully, but these errors were encountered: