Commit f597d0ec authored by Ben Mullins's avatar Ben Mullins
Browse files

Issue #3371571 by lauriii, smustgrave: Autocomplete throbber is visible when...

Issue #3371571 by lauriii, smustgrave: Autocomplete throbber is visible when entering a blacklist character
parent f2933175
Loading
Loading
Loading
Loading
+24 −24
Original line number Diff line number Diff line
@@ -212,10 +212,9 @@
  Drupal.behaviors.autocomplete = {
    attach(context) {
      // Act on textfields with the "form-autocomplete" class.
      const $autocomplete = $(
        once('autocomplete', 'input.form-autocomplete', context),
      );
      if ($autocomplete.length) {
      once('autocomplete', 'input.form-autocomplete', context).forEach(
        (element) => {
          const $autocomplete = $(element);
          // Allow options to be overridden per instance.
          const blacklist = $autocomplete.attr(
            'data-autocomplete-first-character-blacklist',
@@ -236,7 +235,8 @@
          $autocomplete.on('compositionend.autocomplete', () => {
            autocomplete.options.isComposing = false;
          });
      }
        },
      );
    },
    detach(context, settings, trigger) {
      if (trigger === 'unload') {
+8 −0
Original line number Diff line number Diff line
@@ -47,6 +47,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
        '#autocomplete_route_name' => 'form_test.autocomplete_1',
      ],
    ];
    $form['autocomplete_4'] = [
      '#type' => 'textfield',
      '#title' => 'Autocomplete 4',
      '#autocomplete_route_name' => 'form_test.autocomplete_1',
      '#attributes' => [
        'data-autocomplete-first-character-blacklist' => '/',
      ],
    ];

    return $form;
  }
+6 −0
Original line number Diff line number Diff line
@@ -36,6 +36,12 @@ module.exports = {
      .drupalLogin({ name: 'user', password: '123' })
      .drupalRelativeURL('/form-test/autocomplete')
      .waitForElementVisible('body', 1000);

    browser
      .setValue('[name="autocomplete_4"]', '/')
      .pause(1000)
      .waitForElementNotPresent('.is-autocompleting');

    // eslint-disable-next-line no-unused-expressions
    browser.expect.element(
      '.js-form-item-autocomplete-3 [data-drupal-selector="autocomplete-message"]',
+11 −7
Original line number Diff line number Diff line
@@ -16,14 +16,18 @@
              .addClass('hidden');
          };

          $input.on('autocompletesearch', (event) => {
          $input.autocomplete({
            search(event) {
              const result = Drupal.autocomplete.options.search(event);
              if (result) {
                $(event.target).addClass('is-autocompleting');
                $(event.target)
                  .siblings('[data-drupal-selector="autocomplete-message"]')
                  .removeClass('hidden');
          });
              }

          $input.autocomplete({
              return result;
            },
            response(event) {
              classRemove($(event.target));
            },