Revision: 2543
          https://sourceforge.net/p/mrbs/code/2543/
Author:   cimorrison
Date:     2012-10-30 11:51:36 +0000 (Tue, 30 Oct 2012)
Log Message:
-----------
Fixed some HTML5 validation issues

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

Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc        2012-10-30 11:50:56 UTC (rev 2542)
+++ mrbs/trunk/web/functions.inc        2012-10-30 11:51:36 UTC (rev 2543)
@@ -958,6 +958,7 @@
 //                        casts the keys to integers and the array becomes a 
simple array)
 //        'value'         The value of the input.  Default ''.   Can be a 
single value
 //                        or an array of values.
+//        'size'          The value of the 'size' attribute.  Default NULL
 //        'disabled'      Whether the field should be disabled.  Default FALSE
 //        'create_hidden' Boolean.  If TRUE hidden inputs are created if 
'disabled' is set
 //                        Default TRUE
@@ -969,7 +970,7 @@
 function generate_select($params)
 {
   // some sanity checking on params
-  foreach (array('label', 'name', 'id', 'options', 'force_assoc', 'value',
+  foreach (array('label', 'name', 'id', 'options', 'force_assoc', 'value', 
'size',
                  'disabled', 'create_hidden', 'mandatory', 'multiple', 
'attributes') as $key)
   {
     if (!isset($params[$key]))
@@ -1003,6 +1004,35 @@
     }
   }
   
+  // Some checking that we're obeying the HTML5 rules.   A bit pedantic, but
+  // helps with debugging.  Only carry out these checks if we're going to be
+  // able to report them.
+  if (error_reporting() & E_USER_NOTICE)
+  {
+    if ((!isset($params['size']) || ($params['size'] == 1)) &&
+        $params['mandatory'] &&
+        !$params['multiple'])
+    {
+      if (count($params['options']) == 0)
+      {
+        $message =  "A select element with a required attribute and without a 
multiple " .
+                    "attribute, and whose size is 1, must have a child option 
element.";
+        trigger_error($message, E_USER_NOTICE);
+      }
+      else
+      {
+        $first_child = each($params['options']);
+        if (($first_child['key'] != '') && ($first_child['value'] != ''))
+        {
+          $message = "The first child option element of a select element with 
a required " .
+                     "attribute and without a multiple attribute, and whose 
size is 1, " .
+                     "must have either an empty value attribute, or must have 
no text content.";
+          trigger_error($message, E_USER_NOTICE);
+        }
+      }
+    }
+  }
+  
   if (!is_array($params['value']))
   {
     $params['value'] = array($params['value']);

Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php       2012-10-30 11:50:56 UTC (rev 
2542)
+++ mrbs/trunk/web/systemdefaults.inc.php       2012-10-30 11:51:36 UTC (rev 
2543)
@@ -517,6 +517,14 @@
 // to 'Coffee, Tea and Biscuits', without having to alter the database.   It 
can also
 // be useful if the database table is being shared with another application.
 // MRBS will auto-detect whether the array is associative.
+//
+// If you want to make the select field a mandatory field (see below) then 
include
+// an empty string as one of the values, eg
+//
+//$select_options['entry.catering'] = array(''  => 'Please select one option',
+//                                          'c' => 'Coffee', 
+//                                          's' => 'Sandwiches',
+//                                          'h' => 'Hot Lunch');
 
 
 $datalist_options = array();
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to