Problem with dynamic events .on()
There is a code that dynamically inserts an event, but the event doesn't work out if it is changed from the default value. The event inserts correctly. Where is the problem?
- (function($) {
jQuery.fn.validate = function(options) {
//Настройки
var settings = $.extend({
"main_form_event_type" : "change",
"fild_settings" : { },
}, options);
var $this = this;
//Plugin initialization
function init_validate(){
//Check settings for the element
$($this).find("input:not(:submit),text").each(function(){
var name = $(this).attr("name");
//Check the event
event = settings.main_form_event_type;
if (settings.fild_settings[name] != undefined){
if (settings.fild_settings[name]["event"] != undefined){
event = settings.fild_settings[name]["event"];
}
}
//Set the event
$(this).on(event,function(){
alert("ss");
});
});
}
return this.each(function() {
init_validate();
});
};
})(jQuery);
$(".form-horizontal").validate({
fild_settings:{"name":{"event":["click"],"errror_show":[".ss"]}},
});
live example