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.

80 lines
2.3 KiB

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