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! 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>
'''
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire