0
When giving a console.log(this), I wanted the console’s THIS to return Vue, not Validate’s This,
this.$ValidateUtil({ el: this.$refs.cadMain, rules: { cep: { required: true, regex: /^\d{5}-\d{3}$/ } }, messages: { cep: { regex: "CEP inválido" } }, submitHandler: function () { // AQUI!! -->>console.log(this); return false; } })
import Vue from 'vue'
import 'jquery-validation'
var LibsUtil = (function () {
function LibsUtil() {
}
LibsUtil.ValidateUtil = function (options) {
options = options || {}
$(options.el).validate({
rules: options.rules || {},
messages: options.messages || {},
submitHandler: function (form) {
if (typeof options.submitHandler !== 'undefined') {
options.submitHandler(this, form)
}
return false;
}
})
Return Vue;
};
LibsUtil.install = function (Vue) {
Vue.ValidateUtil = LibsUtil.ValidateUtil;
if (!Vue.prototype.hasOwnProperty("$ValidateUtil")) {
Vue.prototype.$ValidateUtil = LibsUtil.ValidateUtil;
}
};
return LibsUtil;
}());
export { LibsUtil };
export default LibsUtil;
Got it! instead of calling it options.submitHandler(this, form), I call it that: options.submitHandler.call(Vue,this, form)! ^^
– Adolfo Moro