2
votes

I've been trying to get this to work for a moment now but I haven't figured out a solution. I've read about the VeeValidate dynamical fields but it didn't help either. I've the following error :

Uncaught (in promise) Error: [vee-validate] Validating a non-existent field: "#29". Use "attach()" first.

My code :

<!-- Nom de la catégorie du soin -->
                        <b-row>
                            <b-col sm="3">
                                <label>Catégorie du soin</label>
                            </b-col>

                            <!-- List or typing -->
                            <template v-if="vCatState === 'list'">
                                <b-col sm="7">
                                    <b-form-select key="a" v-model="vCategorie" id="categorySoin"
                                     @change="changeListOfServices(vCategorie)" v-validate="'required'" name="catégorie liste">

                                        <option></option>
                                        <option v-for="categoriesoin in categoriesoins" :key="categoriesoin.id" v-bind:value="categoriesoin.id">
                                            {{categoriesoin.name}}
                                        </option>

                                    </b-form-select>
                                    <span>{{ errors.first('catégorie liste') }}</span>
                                </b-col>
                            </template>
                            <template v-else-if="vCatState === 'typing'">
                                <b-col sm="7">
                                    <b-form-input key="b" type="text" v-model="vCat" id="catSoin"
                                    v-validate="'required'" name="catégorie texte"
                                    />
                                    <span>{{ errors.first('catégorie texte') }}</span>
                                </b-col>
                            </template>

                            <b-col sm="2">
                                <b-button @click="catSoin()">
                                    <font-awesome-icon icon="pen-square"/>
                                </b-button>
                            </b-col>
                        </b-row>

I have a "select" and "text" to switch from. When I close the my modal, I run this : this.$validator.reset();

The problem is that I get the error mentionned above if I open the modal by editing a row with dynamic field of type "a" and then editing a row of type "b"

Thanks for reading

1

1 Answers

0
votes

I had this issue whenever showing a modal via a vue component.

I solved this by uniquely assigning a randing key direct

<modal
    :edited-index="editedIndex"
    :dialog="dialog"
    :key="uniqueKey"
    @dialogAction="executeAction"
/>

It's important to reset the modal state to randomly assign a value to the key on modal open event.