Scriptaculous ajax autocomplete empty answer

Im working with ajax autocomplete which works great. My goal is to redirect between the edit function of an existing item or the create function for an item not found.

I insert a specific identifier in each li, and therefore I can use it for the editing function with the afterUpdateElement option.

But if no results were found, the list is empty, and I cannot find a way to tell the afterUpdateElement script that no results were found. Indeed, noUpdateElement is not called because there is no choice. Therefore afterUpdateElement is useless ...

I was thinking of testing the full value sent using an ajax request. But I did not find how to capture him ...

+3
source share
2 answers

So, I finally found a way to check if the results were selected or not (with Gwyohm's huge help):

  • First of all, we set up a hidden field that will be written if the result was selected (true / false). The default value is FALSE.
  • AfterUpdateElement is used only after selection. Therefore, we use this aferUpdateElement element to turn our hidden field into TRUE.
  • , , , afterUpdateElement, - TRUE. - . , FALSE. , Enter, . , , keypress. , , :

    $(id-of-text-field).observe( "keyup", function (e) {

    if (window.event) keycode = window.event.keyCode;
      else if (e) keycode = e.which;
      if (keycode!= 13) {

         
      

    $(ID-- ).value = "FALSE";

      
      

    }

    } bindAsEventListener ($ (ID-- )));.

, , ...

: , , , , , . ( , , ...)

+1

updateChoices :

Ajax.Autocompleter.prototype.updateChoices =  function (choices) {
if(!this.changed && this.hasFocus) {

      if(!choices) {
        //do your "new item" thing here
      }
      else {
         this.update.innerHTML = choices;
         Element.cleanWhitespace(this.update);
         Element.cleanWhitespace(this.update.down());

         if(this.update.firstChild && this.update.down().childNodes) {
           this.entryCount =
             this.update.down().childNodes.length;
           for (var i = 0; i < this.entryCount; i++) {
             var entry = this.getEntry(i);
             entry.autocompleteIndex = i;
             this.addObservers(entry);
           }
         } else {
           this.entryCount = 0;
         }

         this.stopIndicator();
         this.index = 0;

         if(this.entryCount==1 && this.options.autoSelect) {
           this.selectEntry();
           this.hide();
         } else {
           this.render();
         }
      }
   }
}

controls.js. .js .

: pff.. , / TextMate . , . , ,

      if(!choices) {
        //do your "new item" thing here
      }
      else {}

. , , , .

+1

Source: https://habr.com/ru/post/1704955/


All Articles