简体   繁体   中英

Prevent Default Action with jQuery Autocomplete

I have a jQuery Autocomplete input field on a web page. Results are retrieved from a database, but in the case of no results being found, I actually have an option saying "No Results Found". Now, if a user selects "No Results Found" option, I want the field to display the previously selected value. Does anyone have an idea of how to do this?

Couple of tips,

  1. Show the code.
  2. When u mean "Previously selected value". What if the user search something first time which is not in the database.
  3. If you user doesn't gets the response from the database,when it is empty or null,set the -no result-
  4. Worst case, if you wish to show previous result,copy it to temp variable,in onchange() event.

I'm assuming you have a field with the selected item's value? I also assume you know how to retrieve the value of the previously selected item? If not, let me know. With those assumptions made, you could do the following in the on click event function:

if(selectedItem == "No Results Found")
  {
    ui.item.value = previouslySelectedItem;
  }

This is how I would do it going on the little info you provided. If you give more, maybe add some code, I can be more specific.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM