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.

88 lines
2.5 KiB

4 years ago
  1. function LoadAutoCompleteTextBoxCustom(url, id, width, data) {
  2. var aValue = id + "_aValue";
  3. var aText = id + "_aText";
  4. var aSearch = id + "_aSearch";
  5. var aCustom = id + "_aCustom";
  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. var a = ui.item.value;
  52. var custom = a.split(":");
  53. $(aText).val(custom[0]);
  54. $(aCustom).val(custom[1]);
  55. $(aValue).val(ui.item.id);
  56. try {
  57. CallBackAutocomplete(id);
  58. } catch (ex) { }
  59. }
  60. }
  61. });
  62. }
  63. function GetItem(id) {
  64. var text = $("#" + id + "_aText").val();
  65. var value = $("#" + id + "_aValue").val();
  66. var DataList = new Array();
  67. DataList[0] = value;
  68. DataList[1] = text;
  69. return DataList;
  70. }
  71. function SetItem(id, data) {
  72. $("#" + id + "_aValue").val(data[0]);
  73. $("#" + id + "_aText").val(data[1]);
  74. }