Here I am using a vue-form generator. I want to validate a form of fields declared as the object of the Vue form generator. In this, while fields are empty form should not navigate to the next step; if any fields are empty, then that field border should become red and not navigate to the next step. I am trying very hard to achieve this but still not do so; if anyone has an idea, please help me.
<div>
<vue-form-g :schema="schema_third" :model="model" :options="formOptions"></vue-form-g>
<span class="prev_next">
<button class="prev_next_btn" @click.prevent="prev()">Previous</button>
<button class="prev_next_btn" @click.prevent="next()">Next</button>
</span>
</div>
vue-form generator
Vue.use(VueFormWizard)
new Vue({
el: '#q-vikreya',
components: {
"vue-form-g": VueFormGenerator.component
},
data() {
return {
step:1,
model: {},
schema_third: {
fields: [{
type: "input",
inputType: "text",
placeholder: "Job title",
required: true,
model: "job_title",
name: "Job_title",
styleClasses: ["half-width col-xs-12 col-sm-6", "job_title"],
validator: VueFormGenerator.validators.text
}, {
type: "input",
inputType: "text",
placeholder: "Experience",
required: true,
model: "Experience",
styleClasses: ["half-width col-xs-12 col-sm-6", "Experience"],
validator: VueFormGenerator.validators.text
}, {
type: "input",
inputType: "text",
placeholder: "Location",
required: true,
model: "Location",
styleClasses: ["half-width col-xs-12 col-sm-6", "job_title"],
validator: VueFormGenerator.validators.text
}, {
type: "input",
inputType: "text",
placeholder: "Industry",
required: true,
model: "Industry",
styleClasses: ["half-width col-xs-12 col-sm-6", "Experience"],
validator: VueFormGenerator.validators.text
}, {
type: "input",
inputType: "text",
placeholder: "Time",
required: true,
model: "Time",
styleClasses: ["half-width col-xs-12 col-sm-6", "job_title"],
validator: VueFormGenerator.validators.text
}, {
type: "input",
inputType: "text",
placeholder: "Time",
required: true,
model: "Time",
styleClasses: ["half-width col-xs-12 col-sm-6", "Experience"],
validator: VueFormGenerator.validators.text
}]
},
formOptions: {
validateAfterLoad: true,
validateAfterChanged: true
}
};
},
<!--/ By using this delimiters we were able to fix the vue.js compatibility with django. since the curly braces between django and-->
<!-- // vue.js conflicted, delimiters helped here to solve the conflicts-->
delimiters: ["<%","%>"],
ready: function() {
console.log('ready');
},
methods: {
prev() {
if(this.checkForm()) {
this.step--;
}
},
next() {
if(this.checkForm()) {
this.step++;
}
},
checkForm: function (e) {
if (this.category && this.title) {
return true;
}
this.errors = [];
if (!this.category) {
this.errors.push('Name required.');
}
if (!this.title) {
this.errors.push('Age required.');
}
e.preventDefault();
},
submitForm: function(){
axios({
method : "POST",
url: "{% url 'PostAd' %}", //django path name
headers: {'X-CSRFTOKEN': '{{ csrf_token }}', 'Content-Type': 'application/json'},
data : {"category":this.category, "title":this.title,
"address":this.address,
"city": this.city,
"state": this.state,
"zip": this.zip,
"price": this.price,
"description": this.description,
"radio_price": this.radio_price,
"Job_title": this.model,
},//data
}).then(response => {
console.log("response");
console.log(response.data);
this.success_msg = response.data['msg'];
window.location.replace('{% url "classifieds" %}') // Replace home by the name of your home view
}).catch(err => {
this.err_msg = err.response.data['err'];
console.log("response1");
console.log(err.response.data);
});
},
}
})
border: solid thin red !important;- Riyaz Khan