for ($i = 1; $i <= self::NUM_OPTION; $i++) {
$defaults['option_status[' . $i . ']'] = 1;
$defaults['option_weight[' . $i . ']'] = $i;
+ $defaults['option_value[' . $i . ']'] = $i;
}
if ($this->_action & CRM_Core_Action::ADD) {
$errors = array();
+ self::clearEmptyOptions($fields);
+
//validate field label as well as name.
$title = $fields['label'];
$name = CRM_Utils_String::munge($title, '_', 64);
$nextIndex = $start + 1;
while ($nextIndex <= self::NUM_OPTION) {
if ($fields['option_value'][$start] == $fields['option_value'][$nextIndex] &&
- !empty($fields['option_value'][$nextIndex])
+ strlen($fields['option_value'][$nextIndex])
) {
$errors['option_value[' . $start . ']'] = ts('Duplicate Option values');
$errors['option_value[' . $nextIndex . ']'] = ts('Duplicate Option values');
public function postProcess() {
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
+ self::clearEmptyOptions($params);
if ($this->_action == CRM_Core_Action::UPDATE) {
$dataTypeKey = $this->_defaultDataType[0];
$params['data_type'] = self::$_dataTypeKeys[$this->_defaultDataType[0]];
$this->ajaxResponse['customField'] = $customField->toArray();
}
+ /**
+ * Removes value from fields with no label.
+ *
+ * This allows default values to be set in the form, but ignored in post-processing.
+ *
+ * @param array $fields
+ */
+ public static function clearEmptyOptions(&$fields) {
+ foreach ($fields['option_label'] as $i => $label) {
+ if (!strlen(trim($label))) {
+ $fields['option_value'][$i] = '';
+ }
+ }
+ }
+
}