浏览代码

Update to unselect method to support "select2-removing" triggers.

The goal here is send off a triggered event to a subscriber that an
element is going to be removed. It hasn't removed yet but would be
after the event fires. I have also added logic to determine if a
subscriber has prevented default. This will prove useful in the future
if a subscriber needs to extend the functionality for other usages.
Andrew Velis 11 年之前
父节点
当前提交
204d4a276e
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      select2.js

+ 9 - 1
select2.js

@@ -2855,7 +2855,15 @@ the specific language governing permissions and limitations under the Apache Lic
                 this.setVal(val);
                 if (this.select) this.postprocessResults();
             }
-            selected.remove();
+
+            var evt = $.Event("select2-removing");
+            evt.val = this.id(data);
+            evt.choice = data;
+            this.opts.element.trigger(evt);
+
+            if (evt.isDefaultPrevented()) {
+                return;
+            }
 
             this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
             this.triggerChange({ removed: data });