]> source.dussan.org Git - nextcloud-server.git/commitdiff
Prevent adding a duplicate to a multiselect
authorMichael Gapczynski <mtgap@owncloud.com>
Fri, 29 Jun 2012 20:44:08 +0000 (16:44 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Sun, 1 Jul 2012 15:36:44 +0000 (11:36 -0400)
core/js/multiselect.js

index ba89c1bb5632ff9a19bdb2f24248773fdb07eb98..c4fd74b0475e746844b554f23d9b94f487de8b45 100644 (file)
                                                if(event.keyCode == 13) {
                                                        event.preventDefault();
                                                        event.stopPropagation();
+                                                       var value = $(this).val();
+                                                       var exists = false;
+                                                       $.each(options,function(index, item) {
+                                                               if ($(item).val() == value) {
+                                                                       exists = true;
+                                                                       return false;
+                                                               }
+                                                       });
+                                                       if (exists) {
+                                                               return false;
+                                                       }
                                                        var li=$(this).parent();
                                                        $(this).remove();
                                                        li.text('+ '+settings.createText);
                                                        li.before(createItem(this));
                                                        var select=button.parent().next();
                                                        var option=$('<option selected="selected"/>');
-                                                       option.attr('value',$(this).val());
+                                                       option.attr('value',value);
                                                        option.text($(this).val());
                                                        select.append(option);
                                                        li.prev().children('input').trigger('click');