added formRule to prevent conflict between barcode and #4, CRM-12965
authorKurund Jalmi <kurund@civicrm.org>
Fri, 12 Jul 2013 10:21:55 +0000 (15:51 +0530)
committerKurund Jalmi <kurund@civicrm.org>
Fri, 12 Jul 2013 10:21:55 +0000 (15:51 +0530)
CRM/Badge/Form/Layout.php

index d27c8814cdf3067e5f17b1d8b54730e81dbe4e61..471b899c4f88d1f8a7e40d76a8cb0893ce078c49 100644 (file)
@@ -106,6 +106,34 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
     $this->add('checkbox', 'is_default', ts('Default?'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->add('checkbox', 'is_reserved', ts('Reserved?'));
+
+    $this->addFormRule(array('CRM_Badge_Form_Layout', 'formRule'));
+  }
+
+  /**
+   * form rule
+   *
+   * @param array $fields  the input form values
+   *
+   * @return true if no errors, else array of errors
+   * @access public
+   * @static
+   */
+  static function formRule($fields) {
+    $errors = array();
+
+    if (CRM_Utils_Array::value(4, $fields['token'])
+      && CRM_Utils_Array::value('add_barcode', $fields)
+      && (CRM_Utils_Array::value('barcode_alignment', $fields) == CRM_Utils_Array::value(4, $fields['text_alignment']))
+    ) {
+      $errors['barcode_alignment'] = ts('You cannot have same alignment for barcode and #4 row.');
+    }
+
+    if (!empty($errors)) {
+      return $errors;
+    }
+
+    return empty($errors) ? TRUE : $errors;
   }
 
   /**