To reproduce

  1. create a new Autocompletion Configuration, and check that "Minimum keyword size that uncouple autocomplete search" is set to for example "3".
  2. Go to a search box and type a single character and see that autocomplete is activated.
CommentFileSizeAuthor
#16 interdiff.txt356 bytesDom.
#16 min_length_option_not_used--2821680-16.patch947 bytesDom.
#15 min_length_option_not_used--2821680-15.patch959 bytesDom.
#11 Tag issue.png10.7 KBriddhi.addweb
#10 restrict_mincharacter-2821680-10.patch3.16 KBUjwala_D
#9 After patch.png23.93 KBriddhi.addweb
#5 restrict_mincharacter-2821680-5.patch1.71 KBUjwala_D
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ressa created an issue. See original summary.

ressa’s picture

Issue summary: View changes
sittard’s picture

Confirming same issue as reported above with the search block and autocompletion_callbacks_words::words_autocompletion_callback as the callback.

Frequently results in the user getting the warning message on the subsequent page load.

You must include at least one keyword to match in the content. Keywords must be at least 3 characters, and punctuation is ignored.

Thanks

Dom.’s picture

Hi ! thanks for reporting, I will have a look as soon as possible.

Ujwala_D’s picture

Status: Active » Needs review
FileSize
1.71 KB

Hi,

I have created patch, in which minimum character has been validate to activate the result.
PFA of patch file.

Thanks

sittard’s picture

Ujwala_D’s picture

Hi sittard,

I have checked the patch given in 'Possible duplicate: https://www.drupal.org/node/2839543'. But those changes are related to setting 'maximum number of suggestion to display' not to 'minimum number of character a user must input before auto completion starts'.

I think this issue is related to restrict the number character user enters in search textbox. So Please go through the patch which is have created in comment #5.

Thanks

sittard’s picture

On further reading I see you are correct - thanks.

riddhi.addweb’s picture

Status: Needs review » Needs work
FileSize
23.93 KB

@Ujwala_D,Thanks! for the patch, it works well, but face some issue during RTBC
like.1) When I tried autocomplete functionality with Tags Field it didn't work for me Also there is no option to check for "Use Autocomplete".
2) When I use filter with Body it shows <P> tag with suggested value.PFA

riddhi.addweb’s picture

FileSize
10.7 KB

@Ujwala_D,Thanks! for the patch solution it works for tag field now but when i use it it shows me count with results.

Steps to reproduce #2 issue :-

1) Install Search Auto complete and view auto complete filters and enable it.

2) Create new view.

3) Add fields for like title, body and tags.

4) Create Expose Filter for body,Title & tag field. Select operator as "contains" from drop down.

5) In the filter settings also select use auto select checkbox, and also set minimum number of characters to start filter as 3.

6) Save that View.

7) In Body filter write content and you will see

tags in textbox, if you select that value as a selected value it reflects

with that value also.

Note : For better clarity i can provide you my simplytestMe link if you want.

Ujwala_D’s picture

Hi Jigar.addweb,

I able to reproduce the issue for body field with 'minimum number of character to start filter' settings. But This issue is related to 'views autocomplete filters' module not to search autocomplete module.
So you can raise same issue for 'views autocomplete filters' module.
One more thing, regarding the showing count with result in tags fields, Its a drupal default behaviour, Even if you uninstall the search autocomplete module, It remain same as you get before.

Still you have any issue let me know.

Thanks

mortona2k’s picture

Status: Needs work » Reviewed & tested by the community

This patch is working for me. It sounds like the issue above should be addressed somewhere else. Thanks for your work on this!

Dom.’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/js/jquery.autocomplete.js
    @@ -104,14 +104,22 @@
    +        response(suggestions);
    +      }else{
    +        suggestions = [];
    +        response(suggestions);
           }
    -      response(suggestions);
    

    Keep the last response(suggestions) since it is done in each cases

  2. +++ b/js/jquery.autocomplete.js
    @@ -104,14 +104,22 @@
    +      var taggedChar = request.term;
    +      var minChar = autocomplete.options.forms[key].minChars;
    +      if(taggedChar.length >= minChar){
    +
    +        var tagged = autocomplete.splitValues(request.term);
    +        for (var i = 0, il = tagged.length; i < il; i++) {
    +          var index = suggestions.indexOf(tagged[i]);
    +          if (index >= 0) {
    +            suggestions.splice(index, 1);
    +          }
             }
    +        response(suggestions);
    +      }else{
    +        suggestions = [];
    +        response(suggestions);
    

    This seems useless since if here, we should allow autocompletion. 'search' event, handled via 'searchHandler' method is here to ensure that.

    Best would be to personnalize minLength value per instance, just how it is done for blacklist characters.

  3. +++ b/search_autocomplete.libraries.yml
    @@ -7,4 +7,9 @@ search_autocomplete.admin.helper:
    -    - core/drupal
    ...
    +    - core/drupal
    +    ¶
    +search_autocomplete.user.search_helper:
    +  version: VERSION
    +  js:
    +    js/jquery.autocomplete.js: {}
    
    +++ b/search_autocomplete.module
    @@ -176,17 +176,6 @@ function search_autocomplete_library_info_build() {
    - * Implements hook_library_info_alter().
    - */
    -function search_autocomplete_library_info_alter(array &$libraries, $extension) {
    -  if ($extension == 'core' && isset($libraries['drupal.autocomplete'])) {
    -    $libraries['drupal.autocomplete']['js'] = array(
    -      '/' . drupal_get_path('module', 'search_autocomplete') . '/js/jquery.autocomplete.js' => array(),
    -    );
    -  }
    -}
    -
    -/**
    
    @@ -237,6 +226,7 @@ function search_autocomplete_form_alter(&$form, \Drupal\Core\Form\FormStateInter
    +    $form['#attached']['library'][] = 'search_autocomplete/search_autocomplete.user.search_helper';
    
    @@ -244,6 +234,7 @@ function search_autocomplete_form_alter(&$form, \Drupal\Core\Form\FormStateInter
    +    $form['#attached']['library'][] = 'search_autocomplete/search_autocomplete.user.search_helper';    ¶
    

    Should not be here. How JS is added is another issue.

Dom.’s picture

According to my review in comment #14:
For me patch #10 is not a proper solution. The workflow is that search event is triggered if options passes (minLength included), then the HTTP request to get the results is performed. After that the patch adds another check for minLength to eventually cancel the autocompletion. This is odd and has poor performance.

Better would be to customize minLength value per instance (just has done with "firstCharacterBlacklist"), thus it would be included in 'search' event verif, before AJAX call is done.

Here is a patch attached with this approach.

sittard’s picture

I agree with @Dom - As a quick fix we also changed jquery.autocomplete.js

    // Only search when the term is at least the minimum length.
    return term.length >= options.minLength;

to:

    // Only search when the term is at least the minimum length.
    return term.length >= 3;

That seems to work but obviously the patched solution should get the minLength from the configuration.

Thanks.

Dom.’s picture

@sittard: the patch I provide at #16 has a configurable minLength.

apmsooner’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #16 works fine for me.

ressa’s picture

Status: Reviewed & tested by the community » Closed (cannot reproduce)

This seems to no longer be an issue, so closing this issue.

Manuel Garcia’s picture

Status: Closed (cannot reproduce) » Reviewed & tested by the community

@ressa there are multiple people reporting on the patch fixing the problem, I think this is still valid bug.

doublealpha’s picture

@ressa: I am also facing this issue still. Minimum keyword size was set to 3 in configuration but suggestions were activating after entering a single character. #16 fixed it.

ressa’s picture

I might have originally created (2016) and tested (2019, #20) the issue in Drupal 7, but I agree that we should keep the issue open if it still happens in Drupal 8.

  • Dom. committed 8bca387 on 8.x-1.x
    Issue #2821680 by Dom., Ujwala_D, riddhi.addweb: Minimum keyword size is...
Dom.’s picture

Status: Reviewed & tested by the community » Fixed

Thanks a lot for help and review.

Status: Fixed » Closed (fixed)

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