vendredi 2 octobre 2020

laravel vuejs validation array of pushed inputs

i need to validate array of pushed inputs by vue.js the problem i can't get validation error message for every input, i can't displaying errors resulting from Laravel Array validation in vue js. Anyone any pointers? i get error "Cannot read property '0.upstreamlevel' of undefined"
Thanks in advance! enter image description here enter image description here laravel controller '''

$rules = [
            '*.upstreamlevel' => 'required',
            '*.downstreamlevel' => 'required',
        ];

        $Messages = [
            '*.upstreamlevel.required' => '  please enter upstream',
            '*.downstreamlevel.required' => 'please enter downs',
        ];
        $this->validate($request, $rules, $Messages);

'''

vuejs template

'''

<template>
  <div v-for="(aRecord, index) in listOfRecords">
                               
<input type="text" v-model="aRecord.upstreamlevel" id="upstreamlevel"
 name="upstreamlevel[]" class="form-control">
<div v-for="(error,  index) in errors">
<strong></strong>

 <input type="text" v-model="aRecord.downstreamlevel" id="downstreamlevel"
   name="downstreamlevel[]" class="form-control">
<div v-for="(error,  index) in errors">
<strong></strong>
</div>
</template>
<script>
    export default {
        data() {
            return {
                listOfRecords: {},
                month: null,
                year: null,
                daysList:0,
                structures: [],
                errors : {},
            }
        },
    methods: {},
        AddNew: function () {
                axios.post(`/new`, this.listOfRecords)
        }
        getDays: function (event) {
                // `this` inside methods points to the Vue instance
                this.daysList = new Date(this.year, this.month, 0).getDate();
                this.listOfRecords=[];
                for (let i = 1; i < this.daysList; i++) {
                    this.listOfRecords.push(
                        {
                            daytime: i+'/'+this.month+'/'+this.year,
                            upstreamlevel: '',
                            downstreamlevel: '',
                        }
                    );
                }
            }
 }
</script>

'''



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/30rrxR2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire