Form Reset Can't Clear jQuery Autocomplete
In ASP.NET, I've got a开发者_如何学C user control which appears on each page presenting the user with some options for searching. The control contains a 'Reset' button to clear all the fields and I'm trying to handle that all client side. The control contains, textboxes, date controls, dropdownlists - and a jQuery autocomplete. I'm able the clear-out every field except the autocomplete with:
$(document).ready(function () {
$("#<%= btnReset.ClientID %>").click(function () {
$(".txtClear").val('');
$(".ddlClear").attr('selectedIndex', 0);
$(".datepicker").val('__/__/____');
var source = $("#<%= acSCAC.ClientID %>").autocomplete("option", "source");
$("#<%= acSCAC.ClientID %>").autocomplete("option", "source", [""]);
$("#<%= acSCAC.ClientID %>").val("");
$("#<%= acSCAC.ClientID %>").autocomplete("option", "source", source);
return false;
});
});
You'll note one of my failed attempts at clearing out the autocomplete near the end.
I want it set as it was when the page first loaded - with nothing in it.
Is this not possible?
I would think you could just use the destroy method or set the options to an empty array and then reapply the autocomplete data that you want to appear there. (More on the methods tab on this page - http://jqueryui.com/demos/autocomplete/)
$("#<%= acSCAC.ClientID %>").autocomplete("destroy"); //returns input to init status
or
$("#<%= acSCAC.ClientID %>").autocomplete({"source": [""]}); //clears the autocomplete options array
Followed by the following to reload the options array with data from the original source array
$("#<%= acSCAC.ClientID %>").autocomplete({"source": originalsourcearray});
I also put a sample of what I have done up on jsfiddle.net - http://jsfiddle.net/tFkjA/15/
精彩评论