Update js for shortcodeBuilder to check for dupes in members. feature/shortcodeBuilder
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 18 Sep 2019 17:09:15 +0000 (13:09 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 18 Sep 2019 17:09:15 +0000 (13:09 -0400)
Check the members for a duplicate before adding them.

js/shortcodeBuilder.js

index 1f6b289..e3febc8 100644 (file)
@@ -81,12 +81,6 @@ jQuery(function ($) {
     }
     setupAttributes();
     var cache = {};
-    var memberNames = [
-        { label: 'Steve', value: 1 },
-        { label: 'George', value: 2 },
-        { label: 'Dave', value: 3 },
-        { label: 'Banner', value: 4 }
-    ];
     $('#shortcode-members').autocomplete({
         minLength: 2,
         source: function( request, response ){
@@ -106,8 +100,10 @@ jQuery(function ($) {
             var type   = 'members';
             let record = {id: ui.item.value, name: ui.item.label, type: 'members'};
             $('#shortcode-members').val('');
-            shortcodeAttributes['members'].list.push(record);
-            updateShortcode({list: shortcodeAttributes[type].list, type: type, isList: shortcodeAttributes[type].isList});
+            if ( !checkDuplicates( record, shortcodeAttributes[type].list ) ) {
+                shortcodeAttributes['members'].list.push(record);
+                updateShortcode({list: shortcodeAttributes[type].list, type: type, isList: shortcodeAttributes[type].isList});
+            }
         },
         close: function( event, ui ) {
             $('#shortcode-members').val('');