You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

  1. function LoadAutoCompleteTextBox(url, id, width, data) {
  2. var aValue = id + "_aValue";
  3. var aText = id + "_aText";
  4. var aSearch = id + "_aSearch";
  5. if (width != "") {
  6. //$(aText).width(width);
  7. }
  8. //$(aSearch).width($(aText).width());
  9. $(aText).focus(function () {
  10. $(aSearch).val($(aText).val());
  11. $(aSearch).show();
  12. $(aSearch).focus();
  13. $(aText).hide();
  14. $(aSearch).select();
  15. });
  16. $(aSearch).blur(function () {
  17. $(this).hide();
  18. if ($(aSearch).val() == "") {
  19. $(aValue).val("");
  20. $(aText).val("");
  21. }
  22. $(aText).show();
  23. });
  24. $(aSearch).autocomplete({
  25. source: function (request, response) {
  26. $.ajax({
  27. type: "POST",
  28. contentType: "application/json; charset=utf-8",
  29. url: url,
  30. data: "{" + data + ", 'searchText' : '" + request.term + "'}",
  31. dataFilter: function (data) { return data; },
  32. success: function (data) {
  33. response($.map(data.d, function (item) {
  34. return {
  35. value: item.Value,
  36. id: item.Id
  37. }
  38. }))
  39. },
  40. error: function (XMLHttpRequest, textStatus, errorThrown) {
  41. alert("Oops,there is an error in ssytem, please contact HO");
  42. //alert(errorThrown);
  43. //alert(textStatus);
  44. }
  45. });
  46. },
  47. minLength: 1,
  48. select: function (event, ui) {
  49. if (ui.item) {
  50. $(aValue).val(ui.item.id);
  51. $(aText).val(ui.item.value);
  52. try {
  53. CallBackAutocomplete(id);
  54. } catch (ex) { }
  55. }
  56. }
  57. });
  58. }
  59. function GetItem(id) {
  60. var text = $("#" + id + "_aText").val();
  61. var value = $("#" + id + "_aValue").val();
  62. var DataList = new Array();
  63. DataList[0] = value;
  64. DataList[1] = text;
  65. return DataList;
  66. }
  67. function SetItem(id, data) {
  68. $("#" + id + "_aValue").val(data[0]);
  69. $("#" + id + "_aText").val(data[1]);
  70. }