Automatically uncheck the NULL checkbox when data is typed in the value field while...
authorchriskl <chriskl>
Sun, 9 May 2004 06:56:48 +0000 (06:56 +0000)
committerchriskl <chriskl>
Sun, 9 May 2004 06:56:48 +0000 (06:56 +0000)
HISTORY
classes/database/Postgres.php
display.php

diff --git a/HISTORY b/HISTORY
index ee8bf08f8adca40f3b3c4ce74f88340634c3cdff..c52d6d4fa44ab06cb6e3ab51add4371aa7009228 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -24,6 +24,8 @@ Features
 * Create view wizard (Bryan Encina)
 * Allow specification of MATCH, DEFERRABLE and INITIALLY DEFERRED on
   foreign keys.
+* Automatically uncheck the NULL checkbox when data is typed in the value
+  field while editing data.
 
 Bugs
 * Fix pg_dump output for PostgreSQL 7.0.x and 7.1.x
index ec2d4334220bbf1c92cb5d2c37694cbdcc4c09d1..edee221e9cf07e206939888f03e9ffb606316354 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.198 2004/05/09 06:21:27 chriskl Exp $
+ * $Id: Postgres.php,v 1.199 2004/05/09 06:56:48 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -835,9 +835,17 @@ class Postgres extends BaseDB {
         * @param $name The name to give the field
         * @param $value The value of the field.  Note this could be 'numeric(7,2)' sort of thing...
         * @param $type The database type of the field
+        * @param $actions An array of javascript action name to the code to execute on that action
         */
-       function printField($name, $value, $type) {
+       function printField($name, $value, $type, $actions = array()) {
                global $lang;
+               
+               // Determine actions string
+               $action_str = '';
+               foreach ($actions as $k => $v) {
+                       $action_str .= " {$k}=\"" . htmlspecialchars($v) . "\"";
+               }
+               
                switch ($type) {
                        case 'bool':
                        case 'boolean':
@@ -847,14 +855,14 @@ class Postgres extends BaseDB {
                                
                                // If value is null, 't' or 'f'...
                                if ($value === null || $value == 't' || $value == 'f') {
-                                       echo "<select name=\"", htmlspecialchars($name), "\">\n";
+                                       echo "<select name=\"", htmlspecialchars($name), "\"{$action_str}>\n";
                                        echo "<option value=\"\"", ($value === null) ? ' selected="selected"' : '', "></option>\n";
                                        echo "<option value=\"t\"", ($value == 't') ? ' selected="selected"' : '', ">{$lang['strtrue']}</option>\n";
                                        echo "<option value=\"f\"", ($value == 'f') ? ' selected="selected"' : '', ">{$lang['strfalse']}</option>\n";
                                        echo "</select>\n";
                                }
                                else {
-                                       echo "<input name=\"", htmlspecialchars($name), "\" value=\"", htmlspecialchars($value), "\" size=\"35\" />\n";
+                                       echo "<input name=\"", htmlspecialchars($name), "\" value=\"", htmlspecialchars($value), "\" size=\"35\"{$action_str} />\n";
                                }                               
                                break;
                        case 'text':
@@ -862,13 +870,12 @@ class Postgres extends BaseDB {
                                // addCSlashes converts all weird ASCII characters to octal representation,
                                // EXCEPT the 'special' ones like \r \n \t, etc.
                                if ($type == 'bytea') $value = addCSlashes($value, "\0..\37\177..\377");
-                               echo "<textarea name=\"", htmlspecialchars($name), "\" rows=\"5\" cols=\"28\" wrap=\"virtual\">\n";
+                               echo "<textarea name=\"", htmlspecialchars($name), "\" rows=\"5\" cols=\"28\" wrap=\"virtual\"{$action_str}>\n";
                                echo htmlspecialchars($value);
                                echo "</textarea>\n";
                                break;
                        default:
-//                             echo "<input name=\"", htmlspecialchars($name), "\" value=\"", htmlspecialchars($value), "\" size=\"35\" onBlur=\"isEmpty(this);\" />\n";
-                               echo "<input name=\"", htmlspecialchars($name), "\" value=\"", htmlspecialchars($value), "\" size=\"35\" />\n";
+                               echo "<input name=\"", htmlspecialchars($name), "\" value=\"", htmlspecialchars($value), "\" size=\"35\"{$action_str} />\n";
                                break;
                }               
        }
index 800a8022c8953ca4e8027f9066d500fe083d1e63..e2586341ea0f08f77dccb45ccb1e6aa7bb386120 100644 (file)
@@ -9,7 +9,7 @@
         * @param $return_desc The return link name
         * @param $page The current page
         *
-        * $Id: display.php,v 1.36 2004/02/23 07:23:15 chriskl Exp $
+        * $Id: display.php,v 1.37 2004/05/09 06:56:48 chriskl Exp $
         */
 
        // Include application functions
@@ -37,7 +37,8 @@
                        $attrs = &$data->getTableAttributes($_REQUEST['table']);
                        $rs = &$data->browseRow($_REQUEST['table'], $key);
 
-                       echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                       echo "<form action=\"$PHP_SELF\" method=\"post\" name=\"frmedit\">\n";
+                       $elements = 0;
                        $error = true;                  
                        if ($rs->recordCount() == 1 && $attrs->recordCount() > 0) {
                                echo "<table>\n<tr>";
                                        echo $misc->printVal($data->formatType($attrs->f['type'], $attrs->f['atttypmod']));
                                        echo "<input type=\"hidden\" name=\"types[", htmlspecialchars($attrs->f['attname']), "]\" value=\"", 
                                                htmlspecialchars($attrs->f['type']), "\" /></td>";
+                                       $elements++;
                                        echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
                                        echo "<select name=\"format[", htmlspecialchars($attrs->f['attname']), "]\">\n";
                                        echo "<option value=\"VALUE\"", ($_REQUEST['format'][$attrs->f['attname']] == 'VALUE') ? ' selected="selected"' : '', ">{$lang['strvalue']}</option>\n";
                                        echo "<option value=\"EXPRESSION\"", ($_REQUEST['format'][$attrs->f['attname']] == 'EXPRESSION') ? ' selected="selected"' : '', ">{$lang['strexpression']}</option>\n";
                                        echo "</select>\n</td>\n";
+                                       $elements++;
                                        echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
                                        // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS)
                                        if (!$attrs->f['attnotnull']) {
                                                        $_REQUEST['nulls'][$attrs->f['attname']] = 'on';
                                                }
                                                echo "<input type=\"checkbox\" name=\"nulls[{$attrs->f['attname']}]\"",
-                                                       isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
+                                                       isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>\n";
+                                               $elements++;
                                        }
                                        else
                                                echo "&nbsp;</td>";
 
-                                       echo "<td class=\"data{$id}\" nowrap>", $data->printField("values[{$attrs->f['attname']}]",
-                                               $rs->f[$attrs->f['attname']], $attrs->f['type']), "</td>";
+                                       echo "<td class=\"data{$id}\" nowrap>";
+                                       // If the column allows nulls, then we put a JavaScript action on the data field to unset the
+                                       // NULL checkbox as soon as anything is entered in the field.  We use the $elements variable to 
+                                       // keep track of which element offset we're up to.  We can't refer to the null checkbox by name
+                                       // as it contains '[' and ']' characters.
+                                       if (!$attrs->f['attnotnull'])
+                                               echo $data->printField("values[{$attrs->f['attname']}]", $rs->f[$attrs->f['attname']], $attrs->f['type'], 
+                                                                                                       array('onChange' => 'elements[' . ($elements - 1) . '].checked = false;'));
+                                       else
+                                               echo $data->printField("values[{$attrs->f['attname']}]", $rs->f[$attrs->f['attname']], $attrs->f['type']);
+                                       echo "</td>";
+                                       $elements++;
                                        echo "</tr>\n";
                                        $i++;
                                        $attrs->moveNext();