Revision: 2539
          https://sourceforge.net/p/mrbs/code/2539/
Author:   cimorrison
Date:     2012-10-29 15:44:45 +0000 (Mon, 29 Oct 2012)
Log Message:
-----------
Extended support of $datalist_options to the same fields as $select_options

Modified Paths:
--------------
    mrbs/trunk/web/edit_entry.php
    mrbs/trunk/web/edit_users.php
    mrbs/trunk/web/functions.inc
    mrbs/trunk/web/report.php
    mrbs/trunk/web/systemdefaults.inc.php

Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2012-10-29 12:07:23 UTC (rev 2538)
+++ mrbs/trunk/web/edit_entry.php       2012-10-29 15:44:45 UTC (rev 2539)
@@ -179,41 +179,30 @@
 
 function create_field_entry_name($disabled=FALSE)
 {
-  global $name, $select_options, $datalist_options, $maxlength, 
$is_mandatory_field;
+  global $name, $maxlength, $is_mandatory_field;
   
   echo "<div id=\"div_name\">\n";
   
-  $params = array('label'     => get_vocab("namebooker") . ":",
-                  'name'      => 'name',
-                  'value'     => $name,
-                  'disabled'  => $disabled,
-                  'mandatory' => TRUE);
+  // 'mandatory' is there to prevent null input (pattern doesn't seem to be 
triggered until
+  // there is something there).
+  $params = array('label'      => get_vocab("namebooker") . ":",
+                  'name'       => 'name',
+                  'field'      => 'entry.name',
+                  'value'      => $name,
+                  'disabled'   => $disabled,
+                  'mandatory'  => TRUE,
+                  'maxlength'  => $maxlength['entry.name'],
+                  'attributes' => 'type="text" pattern="' . REGEX_TEXT_POS . 
'"');
                   
-  if (!empty($select_options['entry.name']))
-  {
-    $params['options']   = $select_options['entry.name'];
-    generate_select($params);
-  }
-  elseif (!empty($datalist_options['entry.name']))
-  {
-    $params['options']   = $datalist_options['entry.name'];
-    generate_datalist($params);
-  }
-  else
-  {
-    // 'mandatory' is there to prevent null input (pattern doesn't seem to be 
triggered until
-    // there is something there).
-    $params['maxlength'] = $maxlength['entry.name'];
-    $params['attributes'] = 'type="text" pattern="' . REGEX_TEXT_POS . '"';
-    generate_input($params);
-  }
+  generate_input($params);
+
   echo "</div>\n";
 }
 
 
 function create_field_entry_description($disabled=FALSE)
 {
-  global $description, $select_options, $is_mandatory_field;
+  global $description, $select_options, $datalist_options, $is_mandatory_field;
   
   echo "<div id=\"div_description\">\n";
   
@@ -223,10 +212,11 @@
                   'disabled' => $disabled,
                   'mandatory' => 
isset($is_mandatory_field['entry.description']) && 
$is_mandatory_field['entry.description']);
   
-  if (!empty($select_options['entry.description']))
+  if (isset($select_options['entry.description']) ||
+      isset($datalist_options['entry.description']) )
   {
-    $params['options'] = $select_options['entry.description'];
-    generate_select($params);
+    $params['field'] = 'entry.description';
+    generate_input($params);
   }
   else
   {
@@ -615,7 +605,7 @@
 
 function create_field_entry_custom_field($field, $key, $disabled=FALSE)
 {
-  global $custom_fields, $tbl_entry, $select_options;
+  global $custom_fields, $tbl_entry;
   global $is_mandatory_field, $text_input_max;
   
   echo "<div>\n";
@@ -631,12 +621,6 @@ry_field, 
$text_input_max;ions;$disabled=FALSE)tion']) && 
$is_mandatory_field['entry.description']);��������u
K`^+�*L`^+%l`^+�ha^+������0�a^+�����`����k
 K`^+6 
��!�!0���������x�ga^+������K`^+�
 K`^+0����`K`^+o�������a^+u
K`^+��a^+���a^+���a^+�*L`^+x�ga^+�����`����k
 
K`^+�!�!0���������H�Ga^+p�����K`^+�
 K`^+0����`K`^+o����`����X����8+l`^+�p������u
K`^+�*L`^+p����@����k 
K`^+GHIJKMNOP0���������HUa^+�����K`^+�
 K`^+0����0��a^+u
K`^+�ga^+���`^+��a^+���a^+���a^+�*L`^+HUa^+����P����k
 K`^+8Ua^+���������k 
K`^+(Ua^+���������k 
K`^+Ua^+���������k K`^+  ���a^+u
K`^+���a^+`�������`^+e 
K`^+���a^+�����y��`^+e 
K`^+��a^+�����Z��`^+e 
K`^+؄�`^+�ga^+���`^+��a^+��ga^+���a^+���a^+�*L`^+8+l`^+M�`^+�����p�`^+`����0����k
 
K`^+5678:<=>?@BD0����������M�`^+�����u
K`^+%l`^+�����M�`^+e K`^+%l`^+�_@f�S 
Q��l���c�`^+������M�`^+p����@����k 
K`^+u]��      
4Q��U^Qʉ��u������*ēv0���������H��`^+��`^+�������.b^+��.b^+�6�`^+o���������X����������ga^+u
K`^+��ga^+ 
������.b^+��������������������.b^+�����
   {
     generate_checkbox($params);
   }
-  // Output a select box if they want one
-  elseif (!empty($select_options["entry.$key"]))
-  {
-    $params['options'] = $select_options["entry.$key"];
-    generate_select($params);
-  }
   // Output a textarea if it's a character string longer than the limit for a
   // text input
   elseif (($field['nature'] == 'character') && isset($field['length']) && 
($field['length'] > $text_input_max))
@@ -644,7 +628,7 @@
     // HTML5 does not allow a pattern attribute for the textarea element
     generate_textarea($params);   
   }
-  // Otherwise output a text input
+  // Otherwise output an input
   else
   {
     $is_integer_field = ($field['nature'] == 'integer') && ($field['length'] > 
2);
@@ -663,6 +647,7 @@
       $attributes .= ($is_integer_field) ? '' : ' pattern="' . REGEX_TEXT_POS 
. '"';
     }
     $params['attributes'] = $attributes;
+    $params['field'] = "entry.$key";
     generate_input($params);
   }
   echo "</div>\n";

Modified: mrbs/trunk/web/edit_users.php
===================================================================
--- mrbs/trunk/web/edit_users.php       2012-10-29 12:07:23 UTC (rev 2538)
+++ mrbs/trunk/web/edit_users.php       2012-10-29 15:44:45 UTC (rev 2539)
@@ -399,12 +399,6 @@
                     {
                       generate_checkbox($params);
                     }
-                    // Output a select box if they want one
-                    elseif (!empty($select_options["users.$key"]))
-                    {
-                      $params['options'] = $select_options["users.$key"];
-                      generate_select($params);
-                    }
                     // Output a textarea if it's a character string longer 
than the limit for a
                     // text input
                     elseif (($field['nature'] == 'character') && 
isset($field['length']) && ($field['length'] > $text_input_max))
@@ -414,6 +408,7 @@
                     // Otherwise output a text input
                     else
                     {
+                      $params['field'] = "users.$key";
                       generate_input($params);
                     }
                     break;

Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc        2012-10-29 12:07:23 UTC (rev 2538)
+++ mrbs/trunk/web/functions.inc        2012-10-29 15:44:45 UTC (rev 2539)
@@ -604,7 +604,7 @@
 }
 
 
-// Generate an input field with an associated label
+// Generate an ordinary input field, ie an <input>, with an associated label
 //
 //   $params    an associative array holding the function parameters:
 //      MANDATORY
@@ -621,7 +621,7 @@
 //                      can also be included in the string, eg 'type="number" 
min="1" step="1"'.
 //                      Default NULL.  Can be ither a simple string or an 
array of attributes.
 //
-function generate_input($params)
+function generate_simple_input($params)
 {
   // some sanity checking on params
   foreach (array('label', 'name', 'value', 'disabled', 'mandatory', 
'maxlength', 'attributes', 'suffix') as $key)
@@ -688,6 +688,47 @@
 }
 
 
+// Generate an input which will be a <select> element if $select_options is set
+// for the field, otherwise a <datalist> element if $datalist_options is set,
+// otherwise an ordinary <input> field.
+//
+//   $params    an associative array holding the function parameters:
+//      MANDATORY
+//        'name'        The name of the input.
+//      OPTIONAL
+//        'field'       The name of the field, eg 'entry.name' as used by
+//                      $select_options and $datalist_options
+//        'label'       The text to be used for the field label.
+//        'value'       The value of the input.  Default ''
+//        'suffix'      A string that is displayed after the input field
+//        'disabled'    Whether the field should be disabled.  Default FALSE
+//        'mandatory'   Whether the field is a required field.  Default FALSE
+//        'maxlength'   The maximum length of input allowed.   Default NULL 
(no limit)
+//        'attributes'  Additional attributes, allowing HTML5 input types such 
as number and
+//                      email to be used.   Note that additional attributes 
such as min, etc.
+//                      can also be included in the string, eg 'type="number" 
min="1" step="1"'.
+//                      Default NULL.  Can be ither a simple string or an 
array of attributes
+function generate_input($params)
+{
+  global $select_options, $datalist_options;
+  
+  if (isset($params['field']) && isset($select_options[$params['field']]))
+  {
+    $params['options']   = $select_options[$params['field']];
+    generate_select($params);
+  }
+  elseif (isset($params['field']) && 
isset($datalist_options[$params['field']]))
+  {
+    $params['options']   = $datalist_options[$params['field']];
+    generate_datalist($params);
+  }
+  else
+  {
+    generate_simple_input($params);
+  }
+}
+
+
 // Generate a single radio button (useful when you want to arrange the members
 // of a radio group slightly differently from the standard way)
 //

Modified: mrbs/trunk/web/report.php
===================================================================
--- mrbs/trunk/web/report.php   2012-10-29 12:07:23 UTC (rev 2538)
+++ mrbs/trunk/web/report.php   2012-10-29 15:44:45 UTC (rev 2539)
@@ -204,6 +204,10 @@
         // Otherwise output a text input
         else
         {
+          // We don't use generate_input() here because we want to generate a 
<datalist>
+          // and not a <select> if $select_options is set.  That's because if 
we have options
+          // ('tea', 'white coffee', 'black coffee') we want the user to be 
able to type
+          // 'coffee' which will match both 'white coffee' and 'black coffee'.
           if (isset($select_options["entry.$key"]) && 
!empty($select_options["entry.$key"]))
           {
             $params['options'] = $select_options["entry.$key"];
@@ -214,7 +218,7 @@
           }
           else
           {
-            generate_input($params);
+            generate_simple_input($params);
           }
         }
         echo "</div>\n";

Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php       2012-10-29 12:07:23 UTC (rev 
2538)
+++ mrbs/trunk/web/systemdefaults.inc.php       2012-10-29 15:44:45 UTC (rev 
2539)
@@ -532,9 +532,8 @@
 // some users might find an associative array confusing as the key is entered 
in the input
 // field when the corresponding value is selected.
 //
-// At the moment $select_options is only supported as follows:
-//     - Entry table: name field
-//     - Users table: custom fields
+// At the moment $datalist_options is only supported for the same fields as
+// $select_options (see above for details)
 
 
 $is_mandatory_field = array();
------------------------------------------------------------------------------
The Windows 8 Center - In partnership with Sourceforge
Your idea - your app - 30 days.
Get started!
http://windows8center.sourceforge.net/
what-html-developers-need-to-know-about-coding-windows-8-metro-style-apps/
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to