is there any way to temporarily disable events such as onLoadSuccess() from firing ?
This works, but is it the best way of achieving this ?
function eventOff(obj,type,evt){
var opt = obj[type]('options');
if(!opt['__'+evt]) opt['__'+evt] = opt[evt];
opt[evt] = function(e){};
}
function eventOn(obj,type,evt){
var opt = obj[type]('options');
if(typeof(opt['__'+evt]) == 'function') opt[evt] = opt['__'+evt];
}
$('form#head').form({
onLoadSuccess: function(){
console.log('default done message')
}
})
eventOff($('form#head'),'form','onLoadSuccess');
$('form#head').form('load',{xxx:'yyy'});
console.log('OFF-loaded');
eventOn($('form#head'),'form','onLoadSuccess')
$('form#head').form('load',{xxx:'yyy'});
console.log('ON-loaded');
eventOff($('form#head'),'form','onLoadSuccess');
$('form#head').form('load',{xxx:'yyy'});
console.log('OFF-loaded');
I would then like to extend the form so that I can call a preload() method that does not fire the onLoadSuccess event:
$.extend($.fn.form.methods, {
preload: function(jq,data){
return jq.each(function(){
var me = $(this);
eventOff(me,'form','onLoadSuccess');
me.form('load',data);
eventOn(me,'form','onLoadSuccess');
})
},
})