BUG 11421 "CheckGroups option ZERO always selected" SOLVED

- CheckGroups option ZERO always selected
- Problem solved, In Dynaform to the create CheckGroups is validated the value when is zero,
  additionally, is validates to Listbox and CheckGroup when are empty and zero.
* Available from version ProcessMaker-2.0.47 (2.5.1)
This commit is contained in:
Luis Fernando Saisa Lopez
2013-05-06 14:58:41 +00:00
parent b79f9bca5c
commit 5282e9515e
2 changed files with 65 additions and 34 deletions

View File

@@ -61,19 +61,43 @@ class Form extends XmlForm
* @access public
* @return string
*/
public function setDefaultValues ()
{
foreach ($this->fields as $name => $content) {
if (is_object( $content ) && get_class( $content ) != '__PHP_Incomplete_Class') {
if (isset( $content->defaultValue )) {
$this->values[$name] = $content->defaultValue;
switch ($content->type) {
case "checkgroup":
case "listbox":
$defaultValueAux = trim($content->defaultValue);
if ($defaultValueAux != "") {
$this->values[$name] = $content->defaultValue;
} else {
$this->values[$name] = "__NULL__";
}
break;
default:
$this->values[$name] = $content->defaultValue;
break;
}
} else {
$this->values[$name] = '';
switch ($content->type) {
case "checkgroup":
case "listbox":
$this->values[$name] = "__NULL__";
break;
default:
$this->values[$name] = "";
break;
}
}
} else {
$this->values[$name] = '';
}
}
foreach ($this->fields as $k => $v) {
if (is_object( $v )) {
//julichu
@@ -117,6 +141,7 @@ class Form extends XmlForm
trigger_error( 'Faild to create cache file "' . $xmlform->parsedFile . '".', E_USER_ERROR );
}
$this->setDefaultValues();
//to do: review if you can use the same form twice. in order to use once or not.
//DONE: Use require to be able to use the same xmlform more than once.
foreach ($this->fields as $k => $v) {
@@ -229,6 +254,7 @@ class Form extends XmlForm
if (! is_array( $newValues )) {
return;
}
foreach ($this->fields as $k => $v) {
if (array_key_exists( $k, $newValues )) {
if (is_array( $newValues[$k] )) {
@@ -362,9 +388,9 @@ class Form extends XmlForm
$values[$k] = $values[$k . "_label"] = null;
foreach ($newValues[$k] as $i => $value) {
//if $value is empty continue with the next loop, because this is a not selected/checked item
if (trim( $value ) == '') {
continue;
}
//if (trim( $value ) == '') {
// continue;
//}
$values[$k] .= (($i != 0) ? "|" : null) . $value;
@@ -510,8 +536,13 @@ class Form extends XmlForm
}
}
} else {
if ($v->type == 'checkgroup') {
$values[$k] = null;
switch ($v->type) {
case "checkgroup":
case "listbox":
//This value is added when the user does not mark any checkbox
$values[$k . "_label"] = "__NULL__";
$values[$k] = "__NULL__";
break;
}
}
} else {

View File

@@ -3599,6 +3599,15 @@ class XmlForm_Field_Listbox extends XmlForm_Field
if (! is_array( $value )) {
$value = explode( '|', $value );
}
$arrayAux = array();
foreach ($value as $index2 => $value2) {
$arrayAux[] = $value2 . "";
}
$value = $arrayAux;
if ($this->mode === 'edit') {
$itemWidth = '';
if ($this->width != '') {
@@ -3606,10 +3615,10 @@ class XmlForm_Field_Listbox extends XmlForm_Field
}
$html = '<select multiple="multiple" id="form[' . $this->name . ']" name="form[' . $this->name . '][]" size="' . $this->size . '" ' . $itemWidth . ' ' . $this->NSFieldType() . '>';
foreach ($this->option as $optionName => $option) {
$html .= '<option value="' . $optionName . '" ' . ((in_array( $optionName, $value )) ? 'selected' : '') . '>' . $option . '</option>';
$html .= "<option value=\"" . $optionName . "\" " . ((in_array( $optionName . "", $value )) ? "selected=\"selected\"" : "") . ">" . $option . "</option>";
}
foreach ($this->sqlOption as $optionName => $option) {
$html .= '<option value="' . $optionName . '" ' . ((in_array( $optionName, $value )) ? 'selected' : '') . '>' . $option . '</option>';
$html .= "<option value=\"" . $optionName . " \" " . ((in_array( $optionName . "", $value )) ? "selected=\"selected\" " : "") . ">" . $option . "</option>";
}
$html .= '</select>';
@@ -3618,17 +3627,17 @@ class XmlForm_Field_Listbox extends XmlForm_Field
} elseif ($this->mode === 'view') {
$html = '<select multiple="multiple" id="form[' . $this->name . ']" name="form[' . $this->name . '][]" size="' . $this->size . '" ' . $this->NSFieldType() . ' style="background: none;" disabled="disabled">';
foreach ($this->option as $optionName => $option) {
$html .= '<option value="' . $optionName . '" ' . ((in_array( $optionName, $value )) ? 'class="module_ListBoxView" selected="selected"' : '') . '>' . $option . '</option>';
$html .= "<option value=\"" . $optionName . " \" " . ((in_array( $optionName . "", $value )) ? "class=\"module_ListBoxView\" selected=\"selected\"" : "") . ">" . $option . "</option>";
}
foreach ($this->sqlOption as $optionName => $option) {
$html .= '<option value="' . $optionName . '" ' . ((in_array( $optionName, $value )) ? 'class="module_ListBoxView" selected="selected"' : '') . '>' . $option . '</option>';
$html .= "<option value=\"" . $optionName . " \" " . ((in_array( $optionName . "", $value )) ? "class=\"module_ListBoxView\" selected=\"selected\"" : "") . ">" . $option . "</option>";
}
$html .= '</select>';
foreach ($this->option as $optionName => $option) {
$html .= '<input type="hidden" id="form[' . $this->name . ']" name="form[' . $this->name . '][]" value="' . ((in_array( $optionName, $value )) ? $optionName : '') . '">';
$html .= "<input type=\"hidden\" id=\"form[" . $this->name . "]\" name=\"form[" . $this->name . "][]\" value=\"" . ((in_array( $optionName . "", $value )) ? $optionName : "__NULL__") . "\">";
}
foreach ($this->sqlOption as $optionName => $option) {
$html .= '<input type="hidden" id="form[' . $this->name . ']" name="form[' . $this->name . '][]" value="' . ((in_array( $optionName, $value )) ? $optionName : '') . '">';
$html .= "<input type=\"hidden\" id=\"form[" . $this->name . "]\" name=\"form[" . $this->name . "][]\" value=\"" . ((in_array( $optionName . "", $value )) ? $optionName : "__NULL__") . "\">";
}
return $html;
} else {
@@ -3802,20 +3811,20 @@ class XmlForm_Field_CheckGroup extends XmlForm_Field
if (! is_array( $value )) {
$value = explode( '|', $value );
}
$arrayAux = array();
foreach ($value as $index2 => $value2) {
$arrayAux[] = $value2 . "";
}
$value = $arrayAux;
if ($this->mode === 'edit') {
$i = 0;
$html = '';
foreach ($this->options as $optionName => $option) {
$swCheked = 0;
foreach ($value as $index2 => $value2) {
if (strlen($value2 . "") > 0 && $value2 == $optionName) {
$swCheked = 1;
break;
}
}
$html = $html . "<input type=\"checkbox\" id=\"form[" . $this->name . "][" . $optionName . "]\" name=\"form[" . $this->name . "][]\" value=\"" . $optionName . "\"" . (($swCheked == 1) ? " checked=\"checked\" " : "") . "><span class=\"FormCheck\"><label for=\"form[" . $this->name . "][" . $optionName . "]\">" . $option . "</label></span></input>";
$html .= "<input type=\"checkbox\" id=\"form[" . $this->name . "][" . $optionName . "]\" name=\"form[" . $this->name . "][]\" value=\"" . $optionName . "\"" . (in_array( $optionName . "", $value ) ? "checked = \"checked\" " : "") . "><span class=\"FormCheck\"><label for=\"form[" . $this->name . "][" . $optionName . "]\">" . $option . "</label></span></input>";
if (++ $i == count( $this->options )) {
$html .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $this->renderHint();
@@ -3826,17 +3835,8 @@ class XmlForm_Field_CheckGroup extends XmlForm_Field
} elseif ($this->mode === 'view') {
$html = '';
foreach ($this->options as $optionName => $option) {
$swCheked = 0;
foreach ($value as $index2 => $value2) {
if (strlen($value2 . "") > 0 && $value2 == $optionName) {
$swCheked = 1;
break;
}
}
$html = $html . "<input class=\"FormCheck\" type=\"checkbox\" id=\"form[" . $this->name . "][" . $optionName . "]\" value=\"" . $optionName . "\"" . (($swCheked == 1) ? " checked=\"checked\" " : "") . " disabled=\"disabled\"><span class=\"FormCheck\"><label for=\"form[" . $this->name . "][" . $optionName . "]\">" . $option . "</label></span></input><br />";
$html = $html . "<input type=\"hidden\" name=\"form[" . $this->name . "][]\" value=\"" . (($swCheked == 1) ? $optionName : "") . "\">";
$html .= "<input class=\"FormCheck\" type=\"checkbox\" id=\"form[" . $this->name . "][" . $optionName . "]\" value=\"" . $optionName . "\"" . (in_array( $optionName . "", $value ) ? " checked=\"checked\" " : "") . " disabled=\"disabled\"><span class=\"FormCheck\"><label for=\"form[" . $this->name . "][" . $optionName . "]\">" . $option . "</label></span></input><br />";
$html .= "<input type=\"hidden\" name=\"form[" . $this->name . "][]\" value=\"" . ((in_array( $optionName . "", $value )) ? $optionName : "__NULL__") . "\">";
}
return $html;
} else {