JQuery UI Autocomplete - how do I get a user entered value

Disclaimer: I reviewed related issues and could not find a solution to this particular problem.

The scenario is this:

Depending on whether the user selected the offer from the drop-down list or not matches, I want to perform various jQuery ajax actions. How should I do it? The place where I'm stuck is how to grab the input that is now in the autocomplete input text box?

thank

+3
source share
2 answers

Honestly, I'm not sure. If you look at the documentation, the search should work.

. .: D

.

, , , ; selectbox-like, . , . minLength: 0 .

$( ".selector" ).autocomplete({
   search: function(event, ui) {
     $.ajax{
       //Your ajax parameters...

       success: function(data) { //No idea what format your data is in...
         if(data['status'] == false) { //there is no result
           //return your data.
           //Trigger the events you want if the item does no exist.
         }
         else if(data['status'] == true){
            //return data normally.
         }
       }

     }
   }
});
+2

, , select,

    $("#birds").autocomplete({
        source: "search.php",
        minLength: 2,
        select: function(event, ui) {
            log(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
        }
    });

ui.item , , - ( ).

, , this.value.

+2

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


All Articles