Revision: 2301
          http://mrbs.svn.sourceforge.net/mrbs/?rev=2301&view=rev
Author:   cimorrison
Date:     2012-06-21 15:24:36 +0000 (Thu, 21 Jun 2012)
Log Message:
-----------
Used the HTML5 "number" type and "step" attribute for integer custom fields.

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

Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2012-06-21 14:24:16 UTC (rev 2300)
+++ mrbs/trunk/web/edit_entry.php       2012-06-21 15:24:36 UTC (rev 2301)
@@ -649,6 +649,10 @@
   {
     // If it's a mandatory field then add the HTML5 required and pattern 
attributes
     $attributes = (isset($is_mandatory_field["entry.$key"]) && 
$is_mandatory_field["entry.$key"]) ? 'type="text" required pattern="' . 
REGEX_TEXT_POS . '"' : NULL;
+    if (($field['nature'] == 'integer') && ($field['length'] > 2))
+    {
+      $attributes .= 'type="number" step="1"';
+    }
     generate_input($label_text, $var_name, $value, $disabled, NULL, 
$attributes);
   }
   if ($disabled)

Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc        2012-06-21 14:24:16 UTC (rev 2300)
+++ mrbs/trunk/web/functions.inc        2012-06-21 15:24:36 UTC (rev 2301)
@@ -392,7 +392,13 @@
   $html .= "<input" . ((isset($attributes)) ? " $attributes" : "") . " 
id=\"$name\" name=\"$name\"";
   $html .= ($disabled) ? " disabled=\"disabled\"" : '';
   $html .= (isset($maxlength)) ? " maxlength=\"$maxlength\"" : '';
-  $html .= " value=\"" . htmlspecialchars($value) . "\">\n";
+  // Don't give an empty string if it's a number as that's not a valid 
floating point number
+  // and will fail HTML5 validation
+  if (isset($attributes) && (strpos($attributes, 'type="number"') !== FALSE) 
&& ($value != ''))
+  {
+    $html .= " value=\"" . htmlspecialchars($value) . "\"";
+  }
+  $html .= ">\n";
   // and a hidden input if the input box is disabled
   if ($disabled)
   {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to