简体   繁体   中英

How to make ajax auto-complete compulsory?

I want to force the user to select from the auto-complete options.

NB: I do not want to use a drop down menu.

Try using this

var isItemSelected = false;

 //Handler for AutoCompleter OnClientItemSelected event
  function onItemSelected() {
      isItemSelected = true;
  }

  //Handler for textbox blur event
  function checkItemSelected(myTextBox) {
      if (!isItemSelected) {
          alert("Please select item from the list only!");
          myTextBox.focus();
      }
      else {
          //reset isItemSelected
          isItemSelected = false;
      }
  }

And then throw this in the Textbox:

onblur="checkItemSelected(this)"

Well i have this forum for the references .

Forum ,

You'll need to use the select and focus options to support this. Fiddle example

focus: function( event, ui ) {
            $( "#tags" ).val( ui.item.label );
            return false;
        },

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