Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: return $item on onItemRemove callback (easy fix) #585

Closed
tseven opened this issue Oct 2, 2014 · 0 comments
Closed

Feature: return $item on onItemRemove callback (easy fix) #585

tseven opened this issue Oct 2, 2014 · 0 comments

Comments

@tseven
Copy link

tseven commented Oct 2, 2014

Problem:
When acting on the onItemRemove callback, only the value of the option is passed. This doesn't allow us to know which selectized element this remove was performed on.

Other callbacks like onItemAdd(value, $item) return the $item.
I believe all the callbacks should return this information when available wether it's usefulness is immediately obvious or not.

Adding this information to callback is extremely trivial.
Simply adding , $item to the self.trigger('item_remove', value); function will do the trick:

        /**
         * Removes the selected item matching
         * the provided value.
         *
         * @param {string} value
         */
        removeItem: function(value) {
            var self = this;
            var $item, i, idx;

            $item = (typeof value === 'object') ? value : self.getItem(value);
            value = hash_key($item.attr('data-value'));
            i = self.items.indexOf(value);

            if (i !== -1) {
                $item.remove();
                if ($item.hasClass('active')) {
                    idx = self.$activeItems.indexOf($item[0]);
                    self.$activeItems.splice(idx, 1);
                }

                self.items.splice(i, 1);
                self.lastQuery = null;
                if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) {
                    self.removeOption(value);
                }

                if (i < self.caretPos) {
                    self.setCaret(self.caretPos - 1);
                }

                self.refreshState();
                self.updatePlaceholder();
                self.updateOriginalInput();
                self.positionDropdown();
                self.trigger('item_remove', value, $item);
            }
        },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant