Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function processAutoComplete(objEvent, strResult, strTypeOrSubtype) {
- if ($(objEvent.target).closest('.test-section[data-createdviapost]').length === 0) {
- if (strTypeOrSubtype === '.test-type') {
- strResult = strResult.filter(function (strVal) {
- return lstTypeHidden.indexOf(strVal) == -1;
- });
- } else if (strTypeOrSubtype === '.test-subtype') {
- strResult = strResult.filter(function (strVal) {
- return lstSubTypeHidden.indexOf(strVal) == -1;
- });
- }
- }
- $(objEvent.target).closest('.test-section').find('' + strTypeOrSubtype + '').attr("data-source", '[' + strResult.join() + ']');
- let lstDataSource = $(objEvent.target).attr("data-source").replace("[", "").replace("]", "").split(",");
- $(objEvent.target).autocomplete({
- minLength: 0,
- source: function (request, response) {
- var results = $.ui.autocomplete.filter(lstDataSource, request.term);
- response(results.slice(0, 10));
- },
- response: function (event, ui) {
- if (!ui.content.length) {
- ui.content.push({
- label: $Label.NoMatchesFound,
- value: "",
- id: 0
- });
- }
- setTimeout(function () {
- if (stringIsBlank($(event.target).val())) {
- $(event.target).trigger('change');
- }
- }, 500);
- },
- select: function (objSelectEvent, objUI) {
- if (strTypeOrSubtype === '.test-subtype') {
- fireRemoteActionForCaseSubtype(objUI, objEvent);
- } else {
- if (objUI.item) {
- setTimeout(function () {
- $(objEvent.target).trigger('change');
- }, 1000);
- }
- }
- },
- create: function (objEvent, objUI) {
- $(objEvent.target).autocomplete('search', '');
- }
- }).click(function (objClickEvent) {
- var caseValue = '';
- var caseTypeValue = '';
- if (strTypeOrSubtype === '.test-subtype') {
- caseValue = $(objEvent.target).closest('.test-section').find(".test-type").val().trim();
- fireRemoteActionForCaseType(caseValue, objEvent, objClickEvent);
- } else {
- caseValue = $(objEvent.target).closest('.test-section').find(".test-subtype").val().trim();
- caseTypeValue = $(objEvent.target).closest('.test-section').find(".test-type").val().trim();
- fireRemoteActionOnClickAutocomplete(caseTypeValue, caseValue, objEvent);
- }
- }).data("ui-autocomplete")._renderItem = function (ul, item) {
- var term = this.term;
- var strItemLabel = item.label.trim();
- var regex = new RegExp("(" + $.ui.autocomplete.escapeRegex(term) + ")", "ig");
- var label = strItemLabel.replace(regex, '<b style="font-weight: bold;">$&</b>');
- $link = $("<a></a>").html(label);
- if ($(ul).attr("data-targetId") === undefined) {
- $(ul).attr("data-targetId", $(objEvent.target).attr("id"));
- }
- if (strItemLabel.toUpperCase() !== $Label.NoMatchesFound.toUpperCase()) {
- $link = $("<a></a>").html(label);
- return $("<li></li>").append($link).appendTo(ul);
- } else {
- return $("<li class='no-select'>" + label + "</li>").appendTo(ul);
- }
- };
- spinner(false);
- }
- <input type="text" id="CaseType" class="autocomplete case-type" oninput="processAutoComplete(event)" onclick="processAutoComplete(event)"
- required="required" data-apiname= "Type"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement