Merge pull request #1692 from luisfernandosl/BUG-11421

BUG 11421 "CheckGroups option ZERO always selected" SOLVED
This commit is contained in:
julceslauhub
2013-05-07 12:43:26 -07:00
2 changed files with 65 additions and 16 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,12 @@ 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] = "__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,11 +3811,21 @@ 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) {
$html .= '<input id="form[' . $this->name . '][' . $optionName . ']" name="form[' . $this->name . '][]" type=\'checkbox\' value="' . $optionName . '"' . (in_array( $optionName, $value ) ? '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();
}
@@ -3816,8 +3835,8 @@ class XmlForm_Field_CheckGroup extends XmlForm_Field
} elseif ($this->mode === 'view') {
$html = '';
foreach ($this->options as $optionName => $option) {
$html .= '<input class="FormCheck" id="form[' . $this->name . '][' . $optionName . ']" type=\'checkbox\' value="' . $optionName . '"' . (in_array( $optionName, $value ) ? 'checked' : '') . ' 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 : '') . '">';
$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 {