quasar icon indicating copy to clipboard operation
quasar copied to clipboard

Unable prevent submitting a dialog form in case error validation.

Open sontis3 opened this issue 8 years ago • 1 comments

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.

sontis3 avatar Nov 02 '18 10:11 sontis3

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()
}

rstoenescu avatar Nov 03 '18 12:11 rstoenescu