From 59a17524e89a6c1842a20eaaa2152457eb7df6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Chapeaux?= Date: Fri, 22 Mar 2002 14:17:01 +0000 Subject: [PATCH] Improved js controls for null/not null fields and fixed js bugs with the MSIE autocomplete feature --- header.inc.php3 | 7 +++++ libraries/tbl_change.js | 59 +++++++++++++++++++++++++++++++++++++++++ tbl_change.php3 | 42 +++++++++++++++++------------ 3 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 libraries/tbl_change.js diff --git a/header.inc.php3 b/header.inc.php3 index 1c25649e8..f9b0002f5 100755 --- a/header.inc.php3 +++ b/header.inc.php3 @@ -135,6 +135,13 @@ var errorMsg2 = '' +//--> + + + diff --git a/libraries/tbl_change.js b/libraries/tbl_change.js new file mode 100644 index 000000000..fe90ffea7 --- /dev/null +++ b/libraries/tbl_change.js @@ -0,0 +1,59 @@ +/* $Id$ */ + + +/** + * Modify from controls when the "NULL" checkbox is selected + * + * @param string the MySQL field type + * @param string the urlencoded field name + * @param string the md5 hashed field name + * + * @return boolean always true + */ +function nullify(theType, urlField, md5Field) +{ + var rowForm = document.forms['insertForm']; + + if (typeof(rowForm.elements['funcs[' + urlField + ']']) != 'undefined') { + rowForm.elements['funcs[' + urlField + ']'].selectedIndex = -1; + } + + // "SET" field or "ENUM" field with more than 20 characters + if (theType == 1 || theType == 3) { + rowForm.elements['field_' + md5Field + '[]'].selectedIndex = -1; + } + // Other "ENUM" field + else if (theType == 2) { + var elts = rowForm.elements['field_' + md5Field + '[]']; + var elts_cnt = elts.length; + for (var i = 0; i < elts_cnt; i++ ) { + elts[i].checked = false; + } // end for + } + // Other field types + else /*if (theType == 4)*/ { + rowForm.elements['fields[' + urlField + ']'].value = ''; + } // end if... else if... else + + return true; +} // end of the 'nullify()' function + + +/** + * Unchecks the "NULL" control when a function has been selected or a value + * entered + * + * @param string the urlencoded field name + * + * @return boolean always true + */ +function unNullify(urlField) +{ + var rowForm = document.forms['insertForm']; + + if (typeof(rowForm.elements['fields_null[' + urlField + ']']) != 'undefined') { + rowForm.elements['fields_null[' + urlField + ']'].checked = false + } // end if + + return true; +} // end of the 'unNullify()' function diff --git a/tbl_change.php3 b/tbl_change.php3 index 04f03b5c0..e7f3a9fcf 100755 --- a/tbl_change.php3 +++ b/tbl_change.php3 @@ -6,6 +6,7 @@ * Get the variables sent or posted to this script and displays the header */ require('./libraries/grab_globals.lib.php3'); +$js_to_run = 'tbl_change.js'; include('./header.inc.php3'); // Displays the query submitted and its result if (!empty($message)) { @@ -111,8 +112,12 @@ else /** * Displays the form */ - -// Had to put the URI because when hosted on an https server, +// loic1: autocomplete feature of IE kills the "onchange" event handler and it +// must be replaced by the "onpropertychange" one in this case +$chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5) + ? 'onpropertychange' + : 'onchange'; +// Had to put the URI because when hosted on an https server, // some browsers send wrongly this form to the http server. ?> @@ -257,7 +262,7 @@ for ($i = 0; $i < $fields_cnt; $i++) { } else { ?> - ="return unNullify('')" tabindex="" > ' . $cfgFunctions[$j] . '' . "\n"; } // end for @@ -286,20 +291,23 @@ for ($i = 0; $i < $fields_cnt; $i++) { if ($row_table_def['Null'] == 'YES') { echo ' 20) { - echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\'].selectedIndex = -1}; return true" />' . "\n"; + $onclick .= '1, '; } else { - echo ' onclick="if (this.checked) {var elts = document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\']; var elts_cnt = elts.length; for (var i = 0; i < elts_cnt; i++ ) {elts[i].checked = false}}; return true" />' . "\n"; + $onclick .= '2, '; } } else if (strstr($row_table_def['True_Type'], 'set')) { - echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\'].selectedIndex = -1}; return true" />' . "\n"; + $onclick .= '3, '; } else { - echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'fields[' . urlencode($field) . ']\'].value = \'\'}; return true" />' . "\n"; + $onclick .= '4, '; } + $onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\'); this.checked = true}; return true" />' . "\n"; + echo $onclick; } else { echo '  ' . "\n"; } @@ -311,7 +319,7 @@ for ($i = 0; $i < $fields_cnt; $i++) { ?> - + 20) { echo "\n"; ?> - ="return unNullify('')" tabindex=""> "> - ="return unNullify('')" tabindex="" > - + - + ="return unNullify('')" tabindex="" /> - + ="return unNullify('')" tabindex="" />