How to make Ajax.Autocompleter execute a request without input?

I use scriptaculous Ajax.Autocompleter to search with various filters.

http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter

Filters require me to dynamically transfer data to autocomplete, which I successfully learned to do using the following link.

http://www.simpltry.com/2007/01/30/ajaxautocompleter-dynamic-parameters/

Now I have several filters and one search box. How to force autocomplete to execute a query without entering input, but clicking a new filter?

Here is a usage example to clarify. The page loads, there are several filters (only links with onclicks) and one input field with attached autocomplete. I type in a request and an autocomplete request is executed. Then I click on another filter, and I would like another request to be executed with the same request, but with a different filter.

Or more succinctly, how to make autostart to execute a request when I want, instead of entering it depending on the input?

+3
source share
4 answers

I also found that the activate () method works fine. Here is my sample code ....

<script type="text/javascript">
    /*<![CDATA[*/

    var autocomp1 = new Ajax.Autocompleter("search", "AjaxResultsListPlaceholder", "ajaxServerSideSearchHandler.php", {
            frequency: 1,
            minChars: 10,
            indicator: "AjaxWorkingPleaseWaitPlaceholder",
            } );


    /*]]>*/
</script>

<form id="theform">
    <input type="text" id="search" name="search" value="" />
    <input type="button" id="btn_search" name="btn_search" value="Search" onclick="autocomp1.activate();" />
    <div id="AjaxWorkingPleaseWaitPlaceholder" style="display: none; border: 1px solid #ffaaaa;">
    </div>
    <div id="AjaxResultsListPlaceholder" style="display: none;; border: 1px solid #aaffaa;">
    </div>

</form>
+3
source

: . , , . , IE Firefox.

  function fakeKeyPress(input_id) {
    var input = $(input_id);
    if(input.fireEvent) {
      // ie stuff
      var evt = document.createEventObject();
      evt.keyCode = 67;
      $(input_id).fireEvent("onKeyDown", evt);
    } else { 
      // firefox stuff
      var evt = document.createEvent("KeyboardEvent");
      evt.initKeyEvent('keydown', true, true, null, false, false, false, false, 27, 0);
      var canceled = !$(input_id).dispatchEvent(evt);
    }
  }
+2

Looking at the Scriptaculous source to see what happens when you press a key , I suggest you try calling onObserverEvent().

var autoCompleter = new Ajax.Autocompleter(/* exercise for the reader */);
// Magic happens
autoCompleter.onObserverEvent();
+1
source
var autoCompleter = new Ajax.Autocompleter(/* exercise for the reader */);
// Magic happens
autoCompleter.activate();
+1
source

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


All Articles