Working with the Quasar framework, I have created a stepper with several fields in each step. Some of these fields are required, as shown below:
<q-stepper dense v-model="step" ref="stepper" color="primary" animated header-nav>\
<q-step dense :name="1" title="Infos générales" icon="settings" :done="step > 1" :error="step < 3">
<q-card-section class="q-pt-none">
<div class="q-col-gutter-x-md">
<q-input class="full-width" dense v-model="infos.motif" label="Raison *" hint="Détaillez la raison. * Champs requis" :rules="Required"></q-input>
</div>
</q-card-section >
</q-step>
<q-step dense :name="2" title="Mise en copie" icon="assignment" :done="step > 2" >
<q-card-section class="q-pt-none" >
<div class="row items-start content-start" >
<div class="text-subtitle2">A la demande</div>
<selectusers v-bind:users="users" v-bind:model.sync="infos.copiedemande"></selectusers>
</div >\
</q-card-section >
</q-step>
<template v-slot:navigation>
<q-stepper-navigation >
<q-btn v-if="step > 1" flat color="primary" @click="$refs.stepper.previous()" label="Retour" />
<q-btn @click="$refs.stepper.next()" color="primary" :label="step === 2 ? \'Fini\' : \'Continuer\'" class="float-right"/>
</q-stepper-navigation >\
</template >\
</q-stepper>
A computed property named Required is defined as follows: Required() { return [(v) => !!v || 'Saisissez quelque chose :-)'] }, I want the first step to display an error if the infos.motif field is left empty when I change steps.
I am trying to link the :error property from step to the rules of the field but I am facing challenges with this. Any guidance would be highly appreciated.
UPDATE1 A form with a ref has been added to the first page.
<q-stepper dense v-model="step" ref="stepper" color="primary" animated header-nav>
<q-step dense :name="1" ref="step1" title="Infos générales" icon="settings" :done="step > 1" :error="checkform1()">
<q-form ref="myForm1">
The method checkform1() has been implemented to handle this.
checkform1() { return this.$refs.stepper ? this.$refs.stepper.$refs.step1.$refs.myForm1.validate() : true; }
However, I am unable to access my form. When using this.$refs.stepper, the $ref appears to be empty... UPDATE2 A sample has been created on Codepen here