pjsikora / select-box

Automatically exported from code.google.com/p/select-box
1 stars 0 forks source link

default "change" event not fired when custom onChange event created #10

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When create custom onChange event the "change" html event not fired 
due to this block and remove the else statment (line 347)

if (inst && onChange) {
                onChange.apply((inst.input ? inst.input[0] : null), [value, inst]);
            }
            //trigger the change allways after the onChange custome event
            else if (inst && inst.input) {
                inst.input.trigger('change');
            }
- i chage it to 
------------------------------------------------
if (inst && onChange) {
                onChange.apply((inst.input ? inst.input[0] : null), [value, inst]);
            }
            //trigger the change allways after the onChange custome event
            if (inst && inst.input) {
                inst.input.trigger('change');
            }

Original issue reported on code.google.com by itay.ben...@gmail.com on 29 Jan 2013 at 8:10

Attachments:

GoogleCodeExporter commented 8 years ago
hi!

thank you for your contribution. even though the diff in your comment was no 
diff at all, the attached file enabled me to grab all required changes.

jQuery 1.9 introduced some final changes to the attr() usage.
see http://jquery.com/upgrade-guide/1.9/#attr-versus-prop- for details.

i think i managed to follow these changes and my patch to the stock 
jquery.selectbox-0.2.js looks like this:

--- jquery.selectbox-0.2.js  2012-07-17 19:58:42.000000000 +0200
+++ jquery.selectbox-0.2.1.js   2013-03-15 19:23:03.000000000 +0100
@@ -300,7 +300,7 @@
                        sbOptions.appendTo(sbHolder);   
                        sbHolder.insertAfter($target);

-                       $("html").live('mousedown', function(e) {
+                       $(document).on("mousedown", "html", function (e) {
                                e.stopPropagation();          
                                $("select").selectbox('close'); 
                        });
@@ -337,10 +337,14 @@
                                $("#sbSelector_" + inst.uid).text(text);
                        }
                        value = value.replace(/\'/g, "\\'");
-                       $(target).find("option[value='" + value + 
"']").attr("selected", TRUE);
+                       //disable all previus options
+                       $(target).find("option").prop("selected", FALSE);
+                       $(target).find("option[value='" + value + 
"']").prop("selected", TRUE);
                        if (inst && onChange) {
                                onChange.apply((inst.input ? inst.input[0] : null), [value, inst]);
-                       } else if (inst && inst.input) {
+                       }
+            //trigger the change allways after the onChange custome event
+            if (inst && inst.input) {
                                inst.input.trigger('change');
                        }
                },

Original comment by ra...@bhatia.at on 15 Mar 2013 at 6:28

Attachments:

GoogleCodeExporter commented 8 years ago
ps. your indentation and spelling errors have been preserved ;)

Original comment by ra...@bhatia.at on 15 Mar 2013 at 6:29