Make maxlength in edit fields a soft limit

This commit is contained in:
Jakub Vrana 2016-09-19 17:21:41 +02:00
parent 682e86d236
commit 9872229e11
4 changed files with 13 additions and 4 deletions

View file

@ -914,7 +914,7 @@ function input($field, $value, $function) {
// type='date' and type='time' display localized value which may be confusing, type='datetime' uses 'T' as date and time separator
echo "<input"
. ((!$has_function || $function === "") && preg_match('~(?<!o)int~', $field["type"]) ? " type='number'" : "")
. " value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "")
. " value='" . h($value) . "'" . ($maxlength ? " data-maxlength='$maxlength'" : "")
. (preg_match('~char|binary~', $field["type"]) && $maxlength > 20 ? " size='40'" : "")
. "$attrs>"
;

View file

@ -26,6 +26,7 @@ pre, textarea { font: 100%/1.25 monospace; }
input[type=image] { vertical-align: middle; }
input.default { box-shadow: 1px 1px 1px #777; }
input.required { box-shadow: 1px 1px 1px red; }
input.maxlength { box-shadow: 1px 1px 1px red; }
.block { display: block; }
.version { color: #777; font-size: 67%; }
.js .hidden, .nojs .jsonly { display: none; }

View file

@ -460,16 +460,17 @@ function functionChange(select) {
if (selectValue(select)) {
if (input.origType === undefined) {
input.origType = input.type;
input.origMaxLength = input.maxLength;
input.origMaxLength = input.getAttribute('data-maxlength');
}
input.removeAttribute('maxlength');
input.removeAttribute('data-maxlength');
input.type = 'text';
} else if (input.origType) {
input.type = input.origType;
if (input.origMaxLength >= 0) {
input.maxLength = input.origMaxLength;
input.setAttribute('data-maxlength', input.origMaxLength);
}
}
oninput({target: input});
helpClose();
}
@ -793,3 +794,9 @@ function cloneNode(el) {
setupSubmitHighlight(el2);
return el2;
}
oninput = function (event) {
var target = event.target;
var maxLength = target.getAttribute('data-maxlength');
alterClass(target, 'maxlength', target.value && maxLength != null && target.value.length > maxLength); // maxLength could be 0
};

View file

@ -1,5 +1,6 @@
Adminer 4.2.6-dev:
Add accessibility labels to Create Table fields
Make maxlength in edit fields a soft limit
Adminer 4.2.5 (released 2016-06-01):
Fix remote execution in SQLite query