Merge pull request #7565 from MrPetovan/bug/7406-neutralize-enter-in-autocomplete

Prevents Enter from submitting forms in ACL fields
This commit is contained in:
Michael Vogel 2019-08-26 11:37:38 +02:00 committed by GitHub
commit 3c7f7b45cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 6 deletions

View file

@ -109,7 +109,14 @@ ACL.prototype.search = function(){
ACL.prototype.on_search = function(event){ ACL.prototype.on_search = function(event){
if (this.kp_timer) clearTimeout(this.kp_timer); if (this.kp_timer) clearTimeout(this.kp_timer);
this.kp_timer = setTimeout( this.search.bind(this), 1000);
// Triggers an immediate search while preventing form submission
if (event.key === 'Enter') {
this.search();
event.preventDefault();
} else {
this.kp_timer = setTimeout( this.search.bind(this), 500);
}
}; };
ACL.prototype.on_showall = function(event){ ACL.prototype.on_showall = function(event){

View file

@ -1,6 +1,6 @@
<div id="acl-wrapper"> <div id="acl-wrapper">
<input id="acl-search"> <input id="acl-search" autocomplete="off">
<a id="acl-showall">{{$showall}}</a> <a id="acl-showall">{{$showall}}</a>
<div id="acl-list"> <div id="acl-list">
<div id="acl-list-content"> <div id="acl-list-content">

View file

@ -118,7 +118,6 @@
$acl_allow_input.tagsinput({ $acl_allow_input.tagsinput({
confirmKeys: [13, 44], confirmKeys: [13, 44],
cancelConfirmKeysOnEmpty: true,
freeInput: false, freeInput: false,
tagClass: function(item) { tagClass: function(item) {
switch (item.type) { switch (item.type) {

View file

@ -481,9 +481,9 @@
var text = $input.val(), var text = $input.val(),
maxLengthReached = self.options.maxChars && text.length >= self.options.maxChars; maxLengthReached = self.options.maxChars && text.length >= self.options.maxChars;
if (self.options.freeInput && (keyCombinationInList(event, self.options.confirmKeys) || maxLengthReached)) { if (keyCombinationInList(event, self.options.confirmKeys) || maxLengthReached) {
// Only attempt to add a tag if there is data in the field // Only attempt to add a tag if there is data in the field
if (text.length !== 0) { if (self.options.freeInput && text.length !== 0) {
self.add(maxLengthReached ? text.substr(0, self.options.maxChars) : text); self.add(maxLengthReached ? text.substr(0, self.options.maxChars) : text);
$input.val(''); $input.val('');
} }

View file

@ -4,7 +4,7 @@
<button id="acl-showall" class="btn btn-block btn-default"><i class="fa fa-globe"></i> {{$showall}}</button> <button id="acl-showall" class="btn btn-block btn-default"><i class="fa fa-globe"></i> {{$showall}}</button>
</div> </div>
<div class="form-group form-group-search"> <div class="form-group form-group-search">
<input type="text" id="acl-search" class="form-control form-search"> <input type="text" id="acl-search" class="form-control form-search" autocomplete="off">
</div> </div>
<div id="acl-list"> <div id="acl-list">
<div id="acl-list-content"></div> <div id="acl-list-content"></div>