CRM-19769 - Add color field to tag edit form
[civicrm-core.git] / CRM / Core / Form.php
index c694a85252345205d610528026756b60f2725887..eb230d457d4065520ebaf28f3d7425255e7c70df 100644 (file)
@@ -217,6 +217,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     'number',
     'url',
     'email',
+    'color',
   );
 
   /**
@@ -345,6 +346,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     $attributes = '', $required = FALSE, $extra = NULL
   ) {
     // Fudge some extra types that quickform doesn't support
+    $inputType = $type;
     if ($type == 'wysiwyg' || in_array($type, self::$html5Types)) {
       $attributes = ($attributes ? $attributes : array()) + array('class' => '');
       $attributes['class'] = ltrim($attributes['class'] . " crm-form-$type");
@@ -384,6 +386,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
     }
 
+    if ($inputType == 'color') {
+      $this->addRule($name, ts('%1 must contain a color value e.g. #ffffff.', array(1 => $label)), 'regex', '/#[0-9a-fA-F]{6}/');
+    }
+
     if ($required) {
       if ($type == 'file') {
         $error = $this->addRule($name, ts('%1 is a required field.', array(1 => $label)), 'uploadedfile');