Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ajax validation with VueJS
new Vue({
el: '#app',
data: {
formInputs: {},
formErrors: {}
},
methods: {
submitForm: function(e) {
var form = e.srcElement;
var action = form.action;
var csrfToken = form.querySelector('input[name="_token"]').value;
this.$http.post(action, this.formInputs, {
headers: {
'X-CSRF-TOKEN': csrfToken
}
})
.then(function() {
form.submit();
})
.catch(function (data, status, request) {
this.formErrors = data.data;
});
}
}
});
@sadeghian92

This comment has been minimized.

Copy link

commented Apr 1, 2017

Hi, this code has a problem with Firefox. the form variable will be undefined for Firefox browser.
I think you should change line 11 to this:
var form = e.target || e.srcElement;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.