dirty_form
dirty_form copied to clipboard
safari 3.x radio button/checkbox handling vs. dirty_form
Not sure this needs addressing in the source, safari 3 is now obsolete and unlike IE, people tend not to run old versions, this is more of a note in case someone else hits it - dirty_form usually watches for blur, but jquery 1.3.x on safari 3.x doesn't actually fire focus/blur events in certain cases [1] , i.e. for radio buttons and checkboxes (this might be a safari problem rather than a jquery problem). A simple workaround is to set a change handler as well as a blur handler for those elements.
[1] http://dev.jquery.com/ticket/3332
hmm... can't work out how to attach patches.... maybe github expects one to fork even for something so trivial? Let's try a code block.
--- /usr/local/src/dirty_form/jquery.dirtyform.js 2009-09-09 12:10:52.000000000 +0100
+++ jquery.dirtyform.js 2010-02-03 11:35:45.000000000 +0000
@@ -108,16 +108,20 @@
.bind("blur.dirty_form", {inputs: inputs, settings: settings}, $.DirtyForm.input_checker)
.data('initial', $.DirtyForm.input_value($(this)))
});
}else {
inputs.each(function(){
$(this)
.bind("blur.dirty_form", {inputs: inputs, settings: settings}, $.DirtyForm.input_checker)
.data("initial", $.DirtyForm.input_value($(this)));
+ // bodge for safari 3.x which doesn't blur checkboxes and radiobuttons.
+ if ($(this).is(':radio,:checkbox')){
+ $(this)
+ .bind("change.dirty_form", {inputs: inputs, settings: settings}, $.DirtyForm.input_checker);
});
}
});
};
// this is meant for selecting links that will warn about proceeding if there are any dirty forms on the page
$.fn.dirty_stopper = function(){
There's now a configuration to globally set the watched event. I know it's not exactly what you're looking for but it's a step closer.
oh, thanks. IIRC the problem with just "change", say, was that it fires an awful lot for some kinds of input.
Yeah, that's why I went with blur originally. It does make sense to hook checkboxes and radiobuttons to the change event. I was just lazy originally and only wanted to hook them up to one event.