quasar
quasar copied to clipboard
Unable prevent submitting a dialog form in case error validation.
Hi! quasar-framework 0.17.17 I would like to use form validation in add new document dialog, but can not prevent submitting:
<q-dialog ...
prevent-close
ok="OK"
cancel="Cancel"
@ok="onOk"
></q-dialog>
...
async onOk() {
this.$v.addFormFields.$touch();
if (this.$v.addFormFields.$error) {
return;
}
....
}
The problem is that the event handler onOk() invoke after submit.
Hi,
Use the "buttons" scoped slot:
<q-dialog ...
prevent-close
>
<!-- ....... -->
<template slot="buttons" slot-scope="props">
<q-btn color="primary" label="OK" @click="validateAndClose(props.ok)" />
<q-btn flat label="Cancel" @click="props.cancel" />
</template>
</q-dialog>
validateAndClose (ok) {
this.$v.addFormFields.$touch();
if (this.$v.addFormFields.$error) {
return;
}
.....
ok()
}