Don't use type=number if a SQL function is used

This commit is contained in:
Jakub Vrana 2014-01-08 09:07:58 -08:00
parent 5444647f61
commit 683f6eefc7
3 changed files with 17 additions and 5 deletions

View file

@ -809,8 +809,9 @@ function input($field, $value, $function) {
}
$onchange = ($first ? " onchange=\"var f = this.form['function[" . h(js_escape(bracket_escape($field["field"]))) . "]']; if ($first > f.selectedIndex) f.selectedIndex = $first;\" onkeyup='keyupChange.call(this);'" : "");
$attrs .= $onchange;
$has_function = (in_array($function, $functions) || isset($functions[$function]));
echo (count($functions) > 1
? "<select name='function[$name]' onchange='functionChange(this);'" . on_help("getTarget(event).value.replace(/^SQL\$/, '')", 1) . ">" . optionlist($functions, $function === null || in_array($function, $functions) || isset($functions[$function]) ? $function : "") . "</select>"
? "<select name='function[$name]' onchange='functionChange(this);'" . on_help("getTarget(event).value.replace(/^SQL\$/, '')", 1) . ">" . optionlist($functions, $function === null || $has_function ? $function : "") . "</select>"
: nbsp(reset($functions))
) . '<td>';
$input = $adminer->editInput($_GET["edit"], $field, $attrs, $value); // usage in call is without a table
@ -842,7 +843,12 @@ function input($field, $value, $function) {
$maxlength += 7; // microtime
}
// type='date' and type='time' display localized value which may be confusing, type='datetime' uses 'T' as date and time separator
echo "<input" . (preg_match('~int~', $field["type"]) ? " type='number'" : "") . " value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . (preg_match('~char|binary~', $field["type"]) && $maxlength > 20 ? " size='40'" : "") . "$attrs>";
echo "<input"
. ((!$has_function || $function === "") && preg_match('~(?<!o)int~', $field["type"]) ? " type='number'" : "")
. " value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "")
. (preg_match('~char|binary~', $field["type"]) && $maxlength > 20 ? " size='40'" : "")
. "$attrs>"
;
}
}
}

View file

@ -453,12 +453,17 @@ function editingKeydown(event) {
function functionChange(select) {
var input = select.form[select.name.replace(/^function/, 'fields')];
if (selectValue(select)) {
if (input.origMaxLength === undefined) {
if (input.origType === undefined) {
input.origType = input.type;
input.origMaxLength = input.maxLength;
}
input.removeAttribute('maxlength');
} else if (input.origMaxLength >= 0) {
input.maxLength = input.origMaxLength;
input.type = 'text';
} else if (input.origType) {
input.type = input.origType;
if (input.origMaxLength >= 0) {
input.maxLength = input.origMaxLength;
}
}
helpClose();
}

View file

@ -1,5 +1,6 @@
Adminer 4.0.1-dev:
Fix compiled version of Elasticsearch
Don't use type=number if a SQL function is used
Adminer 4.0.0 (released 2014-01-08):
Driver for SimpleDB, MongoDB and Elasticsearch