Skip to content

Commit

Permalink
Fix JS error when autocomplete field is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
teohhanhui committed Apr 6, 2018
1 parent 9b8852e commit 03383ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
}
});

if (0 < autocompleteValue.split(',').length) {
if (0 < autocompleteValue.split(',').filter(String).length) {
var menuElement = element.find('div.menu');

menuElement.api({
on: 'now',
method: 'GET',
url: loadForEditUrl,
beforeSend: function (settings) {
settings.data[choiceValue] = autocompleteValue.split(',');
settings.data[choiceValue] = autocompleteValue.split(',').filter(String);

return settings;
},
Expand All @@ -75,7 +75,7 @@
}

window.setTimeout(function () {
element.dropdown('set selected', element.find('input.autocomplete').val().split(','));
element.dropdown('set selected', element.find('input.autocomplete').val().split(',').filter(String));
}, 5000);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$.fn.extend({
productAutoComplete: function () {
$(this).each(function() {
$(this).dropdown('set selected', $(this).find('input[name*="[associations]"]').val().split(','));
$(this).dropdown('set selected', $(this).find('input[name*="[associations]"]').val().split(',').filter(String));
});

$(this).dropdown({
Expand Down Expand Up @@ -49,7 +49,7 @@
},
onAdd: function(addedValue, addedText, $addedChoice) {
var inputAssociation = $addedChoice.parents('.product-select').find('input[name*="[associations]"]');
var associatedProductCodes = 0 < inputAssociation.val().length ? inputAssociation.val().split(',') : [];
var associatedProductCodes = 0 < inputAssociation.val().length ? inputAssociation.val().split(',').filter(String) : [];

associatedProductCodes.push(addedValue);
$.unique(associatedProductCodes.sort());
Expand All @@ -58,7 +58,7 @@
},
onRemove: function(removedValue, removedText, $removedChoice) {
var inputAssociation = $removedChoice.parents('.product-select').find('input[name*="[associations]"]');
var associatedProductCodes = 0 < inputAssociation.val().length ? inputAssociation.val().split(',') : [];
var associatedProductCodes = 0 < inputAssociation.val().length ? inputAssociation.val().split(',').filter(String) : [];

associatedProductCodes.splice($.inArray(removedValue, associatedProductCodes), 1);

Expand Down

0 comments on commit 03383ae

Please sign in to comment.