RajeshChaudhary345 / dropdown-check-list

Automatically exported from code.google.com/p/dropdown-check-list
0 stars 0 forks source link

Checkboxed not set on mutliple select after refresh [1.2 QA] #161

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
** What steps will reproduce the problem?
-Update the underlying select
-call dropdownchecklist("refresh");
-the label is updated, but not the checkboxes
http://jsfiddle.net/nV98R/2/

** What is the expected output? What do you see instead?
All checkboxes are set correctly

** What is your environment?
-- DropDownCheckList version: 1.2 QA
-- jQuery version: 1.5.1
-- jQuery UI version: 1.8.9
-- Browser and version: Tested in IE8 + FF3.6

** Please provide any additional information below/Please attach sample
html
http://jsfiddle.net/nV98R/2/

Original issue reported on code.google.com by sysi...@gmail.com on 8 Mar 2011 at 8:23

GoogleCodeExporter commented 8 years ago
A simple workaround for this is to destroy the ddcl, edit it, then create it 
again.

    $("#sampleButton").click(function() {
        var arr = [1,5];
        $("#sampleSelect").dropdownchecklist("destroy");
        $("#sampleSelect").val(arr);
        $("#sampleSelect").dropdownchecklist({ emptyText: "no selection", width: 125, icon: {} });
    });

Original comment by Bry...@gmail.com on 8 Mar 2011 at 9:01

GoogleCodeExporter commented 8 years ago
Thanks for your comment! Sadly, in my "real world" app I do a lot more after 
initializing (mouseovers and such) and thus I had to recreate all action 
listeners again, so I thought a refresh would be nice.
I'm going to have a look at it, maybe I find the time to fix it.

Original comment by sysi...@gmail.com on 8 Mar 2011 at 9:44

GoogleCodeExporter commented 8 years ago
Ok, I think I fixed this issue, but I couldn't check all side effects though.
It would be really nice if anyone else could have a look at this, and maybe 
merge this piece of code into the repository (I don't know what's the right 
way, should I suggest a patch or what?)

        refresh: function () {
            var self = this, sourceSelect = this.sourceSelect, dropWrapper = this.dropWrapper;

            var allCheckBoxes = dropWrapper.find("input");
            var allGroups = dropWrapper.find(".ui-dropdownchecklist-group");

            var groupCount = 0;
            var optionCount = 0;
            sourceSelect.children().each(function (index) {
                var opt = $(this);
                var disabled = opt.attr("disabled");
                if (opt.is("option")) {
                    var selected = opt.attr("selected");
                    var anItem = $(allCheckBoxes[optionCount]);
                    self._refreshOption(anItem, disabled, selected);
                    optionCount++;
                } else if (opt.is("optgroup")) {
                    var text = opt.attr("label");
                    if (text != "") {
                        var aGroup = $(allGroups[groupCount]);
                        self._refreshGroup(aGroup, disabled);
                        groupCount++;
                    }
                    opt.children("option").each(function () {
                        var subopt = $(this);
                        var subdisabled = (disabled || subopt.attr("disabled"));
                        var selected = subopt.attr("selected");
                        var subItem = $(allCheckBoxes[optionCount]);
                        optionCount++;
                        self._refreshOption(subItem, subdisabled, selected);
                    });
                }
            });
            // update the text shown in the control
            self._updateControlText();
        }

Original comment by sysi...@gmail.com on 8 Mar 2011 at 10:43

GoogleCodeExporter commented 8 years ago
As you have found, multiple groups threw the option count off and messed up the 
selector refresh.
I have incorporated your fix into the base code, and adjusted the test page to 
include multiple groups. 
When I move 1.2 out of QA and into production, your fix will be part of the 
release.

Thank you for your contribution.

Original comment by womohun...@ittrium.com on 9 Mar 2011 at 1:55

GoogleCodeExporter commented 8 years ago
You're welcome! I think this is a great plugin, and the bug crossed my way, so 
I had to track it down ;-)

Original comment by sysi...@gmail.com on 9 Mar 2011 at 7:40

GoogleCodeExporter commented 8 years ago
Fixed in 1.3 (really, 1.2qa)

Original comment by womohun...@ittrium.com on 13 Apr 2011 at 4:49