jQuery UI AutoComplete: Only allow selected valued from suggested list

前端 未结 9 1945
误落风尘
误落风尘 2020-11-30 22:48

I am implementing jQuery UI Autocomplete and am wondering if there is any way to only allow a selection from the suggested results that are

9条回答
  •  隐瞒了意图╮
    2020-11-30 23:39

    I'm on drupal 7.38 and to only allow input from select-box in autocomplete you only need to delete the user-input at the point, where js does not need it any more - which is the case, as soon as the search-results arrive in the suggestion-popup right there you can savely set:

     **this.input.value = ''**
    

    see below in the extract from autocomplete.js ... So I copied the whole Drupal.jsAC.prototype.found object into my custom module and added it to the desired form with

     $form['#attached']['js'][] = array(
      'type' => 'file',
      'data' => 'sites/all/modules/_autocomplete.js',
     );
    

    And here's the extract from drupal's original misc/autocomplete.js modified by that single line...

    Drupal.jsAC.prototype.found = function (matches) {
      // If no value in the textfield, do not show the popup.
      if (!this.input.value.length) {
        return false;
      }
      // === just added one single line below ===
      this.input.value = '';
    
      // Prepare matches.
    

    =cut. . . . . .

提交回复
热议问题