You forgot to escape the values string before using it in the regular expressions that remove a deleted item's values from the input in Drupal.autocomplete_deluxe.MultipleWidget.Item.prototype.remove.

This means that, if a term or other item includes a regex special character - for example, brackets/parenthesis, for example, in a taxonomy term like "United States of America (USA)", deleting it will remove the element from the page, but won't remove the invisible input element, because the regex that finds it is borked. So, if it is already saved to the database, it'll stubbornly refuse to delete on entity save, even though it will look like it has been deleted.

That function should look like this:

  Drupal.autocomplete_deluxe.MultipleWidget.Item.prototype.remove = function() {
    alert("REMOVE");
    this.element.remove();
    var values = this.widget.valueForm.val();
    var escapedValue = Drupal.autocomplete_deluxe.escapeRegex( this.item.value );    // new
    var regex = new RegExp('( )*""' + escapedValue + '""|' + escapedValue + '( )*', 'gi');   // editted
    console.log(this.widget.valueForm.val, this.widget.valueForm);
    this.widget.valueForm.val(values.replace(regex, ''));
    delete this.widget.items[this.value];
  };

In fact, there are several places where the string going into the regex isn't escaped - $.ui.autocomplete.prototype._renderItem is another one. Not sure if that one causes problems, looks like it might.

The 7.x-2.x branch is riddled with bugs. It should not be the recommended release. 7.x-1.x branch should be brought back until the 7.x-2.x branch is ready.

Comments

sepgil’s picture

Status: Active » Fixed

The only two places that uses regex are _renderItem and the remove function. I've implemented your solution for both functions, since it works for both. The problem with _renderItem was, that if you entered a special character like *, js would throw an error and autocomplete would stop working, but escaping the values solves that problem.

The 7.x-1.x has far more bugs the 2.x branch and additionally it isn't supported any more due the unsupported features. So the 2.x will stay as the recommended release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

d.sibaud’s picture

Status: Closed (fixed) » Needs review

reporting the bug also in the 7.x-2.0-beta2, the alanom modification did the trick.

sepgil’s picture

Status: Needs review » Fixed

This has been fixed in the new release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.