Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. function processAutoComplete(objEvent, strResult, strTypeOrSubtype) {
  2. if ($(objEvent.target).closest('.test-section[data-createdviapost]').length === 0) {
  3. if (strTypeOrSubtype === '.test-type') {
  4. strResult = strResult.filter(function (strVal) {
  5. return lstTypeHidden.indexOf(strVal) == -1;
  6. });
  7. } else if (strTypeOrSubtype === '.test-subtype') {
  8. strResult = strResult.filter(function (strVal) {
  9. return lstSubTypeHidden.indexOf(strVal) == -1;
  10. });
  11. }
  12. }
  13. $(objEvent.target).closest('.test-section').find('' + strTypeOrSubtype + '').attr("data-source", '[' + strResult.join() + ']');
  14. let lstDataSource = $(objEvent.target).attr("data-source").replace("[", "").replace("]", "").split(",");
  15. $(objEvent.target).autocomplete({
  16. minLength: 0,
  17. source: function (request, response) {
  18. var results = $.ui.autocomplete.filter(lstDataSource, request.term);
  19. response(results.slice(0, 10));
  20. },
  21. response: function (event, ui) {
  22. if (!ui.content.length) {
  23. ui.content.push({
  24. label: $Label.NoMatchesFound,
  25. value: "",
  26. id: 0
  27. });
  28. }
  29. setTimeout(function () {
  30. if (stringIsBlank($(event.target).val())) {
  31. $(event.target).trigger('change');
  32. }
  33. }, 500);
  34.  
  35. },
  36. select: function (objSelectEvent, objUI) {
  37. if (strTypeOrSubtype === '.test-subtype') {
  38. fireRemoteActionForCaseSubtype(objUI, objEvent);
  39. } else {
  40. if (objUI.item) {
  41. setTimeout(function () {
  42. $(objEvent.target).trigger('change');
  43. }, 1000);
  44. }
  45. }
  46. },
  47. create: function (objEvent, objUI) {
  48. $(objEvent.target).autocomplete('search', '');
  49. }
  50. }).click(function (objClickEvent) {
  51. var caseValue = '';
  52. var caseTypeValue = '';
  53. if (strTypeOrSubtype === '.test-subtype') {
  54. caseValue = $(objEvent.target).closest('.test-section').find(".test-type").val().trim();
  55. fireRemoteActionForCaseType(caseValue, objEvent, objClickEvent);
  56. } else {
  57. caseValue = $(objEvent.target).closest('.test-section').find(".test-subtype").val().trim();
  58. caseTypeValue = $(objEvent.target).closest('.test-section').find(".test-type").val().trim();
  59. fireRemoteActionOnClickAutocomplete(caseTypeValue, caseValue, objEvent);
  60. }
  61. }).data("ui-autocomplete")._renderItem = function (ul, item) {
  62. var term = this.term;
  63. var strItemLabel = item.label.trim();
  64. var regex = new RegExp("(" + $.ui.autocomplete.escapeRegex(term) + ")", "ig");
  65. var label = strItemLabel.replace(regex, '<b style="font-weight: bold;">$&</b>');
  66. $link = $("<a></a>").html(label);
  67. if ($(ul).attr("data-targetId") === undefined) {
  68. $(ul).attr("data-targetId", $(objEvent.target).attr("id"));
  69. }
  70.  
  71. if (strItemLabel.toUpperCase() !== $Label.NoMatchesFound.toUpperCase()) {
  72. $link = $("<a></a>").html(label);
  73. return $("<li></li>").append($link).appendTo(ul);
  74. } else {
  75. return $("<li class='no-select'>" + label + "</li>").appendTo(ul);
  76. }
  77. };
  78. spinner(false);
  79. }
  80.  
  81. <input type="text" id="CaseType" class="autocomplete case-type" oninput="processAutoComplete(event)" onclick="processAutoComplete(event)"
  82. required="required" data-apiname= "Type"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement