-
Notifications
You must be signed in to change notification settings - Fork 919
Description
Package
v4.x
Description
As a developer working with forms, I rely not only to validation schemas, but also to HTML5 validation. Namely, I use <input required>, <input type="number" min= max=>, and I expect the form to display those errors natively. Most of the time it happens automatically when I use <button type="submit">.
The problem is, if I use u-form inside u-modal, the form goes to the modal body, and the submit button goes to the modal footer. As the result, the submit button can't natively perform form submit, and I have to do something like:
u-button(:disabled="form?.loading" @click="form?.submit") SubmitThis works, but it doesn't trigger HTML5 validation.
What I propose is, in form.submit(), call the native validation before calling onSubmitWrapper:
ui/src/runtime/components/Form.vue
Lines 403 to 405 in 6c083ef
| async submit() { | |
| await onSubmitWrapper(new Event('submit')) | |
| }, |
The code could go like this instead:
async submit() {
const formEl = document.getElementById(formId)
if (formEl?.reportValidity() !== false) {
await onSubmitWrapper(new Event('submit'))
}
}Additional context
No response