Trigger event on item remove

Created on 9 June 2015, over 9 years ago
Updated 15 September 2024, 3 months ago

I needed an event when a item got deleted from the widget, so I added this chunk of code. Maybe this could be added to the module?

  Drupal.autocomplete_deluxe.MultipleWidget.Item.prototype.remove = function () {
    this.element.remove();
    var values = this.widget.valueForm.val();
    var escapedValue = Drupal.autocomplete_deluxe.escapeRegex(this.item.value);
    var regex = new RegExp('()*""' + escapedValue + '""()*', 'gi');
    this.widget.valueForm.val(values.replace(regex, ''));
    delete this.widget.items[this.value];
    // Added trigger to know when an item is deleted.
    $(this.widget.valueForm).trigger('autocompletedelete', [this.widget.items]);
  };
Feature request
Status

Closed: outdated

Version

2.1

Component

Multiple values

Created by

🇧🇪Belgium robin.ingelbrecht

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024