]> git.mxchange.org Git - friendica.git/commitdiff
Prevent tagsinput select element to be submitted without a value when they are required
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 22 Feb 2022 15:09:54 +0000 (10:09 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 24 Feb 2022 02:30:18 +0000 (21:30 -0500)
- This was allowing to submit private messages to the wrong recipient

view/js/friendica-tagsinput/friendica-tagsinput.js
view/templates/acl/message_recipient.tpl

index e3db53df41a6b29d04358ba93ef4e528affcd487..45c00641fdb65bd672925969477a09b87e114045 100644 (file)
 
       // add <option /> if item represents a value not present in one of the <select />'s options
       if (self.isSelect && !optionExists) {
-        var $option = $('<option selected>' + htmlEncode(itemText) + '</option>');
+        var $option = $('<option>' + htmlEncode(itemText) + '</option>');
         $option.data('item', item);
         $option.attr('value', itemValue);
         self.$element.append($option);
         tagsinput = new TagsInput(this, arg1);
         $(this).data('tagsinput', tagsinput);
         results.push(tagsinput);
-
-        if (this.tagName === 'SELECT') {
-          $('option', $(this)).attr('selected', 'selected');
-        }
-
         // Init tags from $(this).val()
         $(this).val($(this).val());
       } else if (!arg1 && !arg2) {
index 07c22f449e4fee59fbf6472d18eab333a991f36f..2c74ed178e9e7b04d3a0d460fc86070dffb5dd4e 100644 (file)
@@ -1,4 +1,4 @@
-<select name="recipient" class="form-control input-lg" id="recipient">
+<select name="recipient" class="form-control input-lg" id="recipient" required>
        {{foreach $contacts as $contact}}
                <option value="{{$contact.id}}"{{if $contact.id == $selected}} selected{{/if}}>{{$contact.name}}</option>
        {{/foreach}}
@@ -48,7 +48,9 @@
                        }
                });
 
+               {{if $selected}}
                // Import existing ACL into the tags input fields.
                $recipient_input.tagsinput('add', acl.get({{$selected}})[0]);
+               {{/if}}
        });
 </script>