sharepoint jquery autocomplete clear textbox if no value -


i created textbox works on autocomplete function based on data list. need clear textbox if user has not selected item or has entered wrong text. below code

$.ajax({         url: "http://address/_vti_bin/lists.asmx",         type: "post",         datatype: "xml",         data: soapenv,         contenttype: "text/xml; charset=\"utf-8\"",         success: function (xmlresponse) {             var domelementarray = $("z\\:row", xmlresponse);             var datamap = domelementarray.map(function () {                 return {                     value: $(this).attr('ows_airportcode'),                     id: $(this).attr('ows_airportcode')                 };             });             var data = datamap.get();              //find sharepoint portal search box (this poor selector, not named sharepoint, inamingcontainer getrs in way)                $("input[title='airportcode required field']").autocomplete(         {             source: data,              minilength: 3,             response: function (event, ui) {                 // ui.content array that's sent response callback.                 if (ui.content.length == 0) {                     $("#empty-message").text("no results found");                 } else {                     $("#empty-message").empty();                 }             }         }         );         }     }); //.ajax   

thanks

you subscribe change event on autocomplete , compare selected value against array of list values match:

.autocomplete({    ...    .change: function( event, ui ) {       var input = $("input[title='airportcode required field']");       var selectedvalue = input.val();       var valid = false;       $.each(data , function (i, item) {          if (item.value === selectedvalue) valid = true;       });        if (valid == false){         // clear input if not found         input.val('');       }    } }) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -