RajeshChaudhary345 / dropdown-check-list

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

Enhancement: onItemClick #162

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Ok, after killing a bug I needed some more functionality: onItemClick
(All valid for v1.2qa)

Maybe this is useful for somebody:
Change the following methods to
            checkBox.click(function (e) {
                var aCheckBox = $(this);
                e.stopImmediatePropagation();
                if (aCheckBox.hasClass("active")) {
                    // Active checkboxes take active action
                    self._syncSelected(aCheckBox);
                    self.sourceSelect.trigger("change", 'ddcl_internal');
                    if (!self.isMultiple && options.closeRadioOnClick) {
                        self._toggleDropContainer(false);
                    }
                    if ($.isFunction(self.options.onItemClick)) {
                        try {
                            self.options.onItemClick.call(aCheckBox, aCheckBox);
                        } catch (ex) {
                            alert('onItemClick callback failed: ' + ex);
                        } 
                    }
                }
            });

and

            item.click(function (e) {
                var anItem = $(this);
                e.stopImmediatePropagation();
                if (!anItem.hasClass("ui-state-disabled")) {
                    // check/uncheck the underlying control
                    var aCheckBox = anItem.find("input");
                    var checked = aCheckBox.attr("checked");
                    aCheckBox.attr("checked", !checked);
                    self._syncSelected(aCheckBox);
                    self.sourceSelect.trigger("change", 'ddcl_internal');
                    if (!checked && !self.isMultiple && options.closeRadioOnClick) {
                        self._toggleDropContainer(false);
                    }
                    if ($.isFunction(self.options.onItemClick)) {
                        try {
                            self.options.onItemClick.call(aCheckBox, aCheckBox);
                        } catch (ex) {
                            alert('onItemClick callback failed: ' + ex);
                        } 
                    }
                } else {
                    // retain the focus even if disabled
                    anItem.focus();
                    self._cancelBlur();
                }
            });

Usage:
$("#mySelect").dropdownchecklist({ onItemClick: myItemClicked });

function myItemClicked (item) {
    alert("value " + item.val() + " checked: " + item.attr("checked"));
}

No intense testing done, and I didn't check it on a radio dropdown. Got some 
work to do, so maybe I'll do some tests later.

I'd appreciate your feedback.

Original issue reported on code.google.com by sysi...@gmail.com on 9 Mar 2011 at 11:08

GoogleCodeExporter commented 8 years ago
I will add this to the wish list.

Original comment by womohun...@ittrium.com on 14 Mar 2011 at 2:31

GoogleCodeExporter commented 8 years ago
Issue 168 has been merged into this issue.

Original comment by womohun...@ittrium.com on 12 Apr 2011 at 9:06

GoogleCodeExporter commented 8 years ago
Issue 175 has been merged into this issue.

Original comment by womohun...@ittrium.com on 12 Apr 2011 at 9:07

GoogleCodeExporter commented 8 years ago
Fixed in 1.3
Thanks for the code -- I used something very similar in this release

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