I trying to invoke a public method of my jquery widget api from a form.submit but I’m having no success. Can anyone help me?
_cleanFormFields: function() {
console.log("ok");
},
_addFormListener: function(map, marker) {
var form = $(".add-form").clone().show();
form.submit(function (event){
event.preventDefault();
_cleanFormFields();
}
}
Why this does not work?? The browser’s console raises “Uncaught ReferenceError: _cleanFormFields is not defined” exception
_cleanFormFieldsis a property of some object, right? So you can’t call it directly, you need to reference it via your object:Or, depending on how
_addFormListener()is invoked you might be able to usethis. But you’d need to keep a reference of thethisfrom_addFormListener()because within the.submit()callbackthiswill be the form element in question: