]> git.joonet.de Git - adminer.git/commitdiff
Don't use type=number if a SQL function is used
authorJakub Vrana <jakub@vrana.cz>
Wed, 8 Jan 2014 17:07:58 +0000 (09:07 -0800)
committerJakub Vrana <jakub@vrana.cz>
Wed, 8 Jan 2014 17:07:58 +0000 (09:07 -0800)
adminer/include/functions.inc.php
adminer/static/functions.js
changes.txt

index 1c4a154293ac5171acc4f4d6d5196997794554f2..7d47e1276334e44fb88fc46d43217033b666c08e 100644 (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>"
+                       ;
                }
        }
 }
index 304952e52f02adb4ed4d1646bdef562eff7e7714..69094b0f91048d89392b0d94f1c60d35bdbdcadd 100644 (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();
 }
index 1c25b100c61897d3b9621557b73668a6fada8372..ab609320006adfa7336150d7b6a7b0a67f1af591 100644 (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