Commit 4776a7cf authored by David Galeano's avatar David Galeano
Browse files

Issue #3307339: Fix tag editing functionality

parent 4bd3d46a
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -24,8 +24,6 @@
        tagify.settings.enforceWhitelist = !$(this).hasClass("autocreate");
        tagify.settings.skipInvalid = !!$(this).hasClass("autocreate");
        tagify.settings.maxTags = $(this).hasClass("limited") ? 1 : Infinity;
        // Enables filtering dropdown items values by string containing and not only beginning.
        tagify.settings.dropdown.fuzzySearch = true;

        // Bind "DragSort" to Tagify's main element and tell
        // it that all the items with the below "selector" are "draggable".
@@ -41,15 +39,12 @@
          tagify.updateValueByDOMTags()
        }

        // onInput event.
        var onInput = Drupal.debounce(function (e) {
          var value = e.detail.value;
        function handleAutocomplete(value){
          tagify.whitelist = null;

          // https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort
          controller && controller.abort();
          controller = new AbortController();

          // Show loading animation meanwhile the dropdown suggestions are hided.
          tagify.loading(true);
          fetch($(input).attr('data-autocomplete-url') + '?q=' + encodeURIComponent(value), {signal: controller.signal})
@@ -67,14 +62,23 @@
              tagify.whitelist = newWhitelistData; // update whitelist Array in-place
              tagify.loading(false).dropdown.show(value) // render the suggestions dropdown
            });
        }

        // onInput event.
        var onInput = Drupal.debounce(function (e) {
          var value = e.detail.value;
          handleAutocomplete(value);
        }, 500);

        // tag added callback
        function onAddTag(e){
          tagify.off('add', onAddTag) // exmaple of removing a custom Tagify event
        }
        // onEditInput event.
        var onEditInput = Drupal.debounce(function (e) {
          var value = e.detail.data.newValue;
          handleAutocomplete(value);
        }, 500);

        // listen to any keystrokes which modify tagify's input
        // Edit input event (When user is editing the tag).
        tagify.on('edit:input', onEditInput)
        // Input event (When user is creating the tag).
        tagify.on('input', onInput)
      });
    }
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ abstract class TagifyJavascriptTestBase extends WebDriverTestBase {
  /**
   * {@inheritdoc}
   */
  public function setUp() {
  public function setUp(): void {
    parent::setUp();
    // Create a new content type.
    $this->drupalCreateContentType(['type' => 'test']);