- Posts: 10
COMMUNITY FORUM
Change multipleSelect with check boxes
- Jordan Ivanov
-
Topic Author
- Offline
- New Member
Less
More
14 years 1 month ago #95090
by Jordan Ivanov
Change multipleSelect with check boxes was created by Jordan Ivanov
I want to change the multipleselect extra field list of K2 Add new article, with check boxes. I did something but not perfect, similar to radiolist:in file administrator/components/com_k2/models/extrafield.php
Code:
case 'multipleSelect': $output=JHTML::_('select.genericlist', $defaultValues, 'K2ExtraField_'.$extraField->id.'[]', 'multiple="multiple"', 'value', 'name',$active); break;
I changed with:
Code:
case 'multipleSelect': $output=JHTML::_('select.checkboxlist', $defaultValues, 'K2ExtraField_'.$extraField->id.'[]', '', 'value', 'name',$active); break;
in file libraries/joomla/html/html/select.phpI add:
Code:
/*custom checkbox*/ function checkboxlist( $arr, $name, $attribs = null, $key = 'value', $text = 'text', $selected = null, $idtag = false, $translate = false ) { reset( $arr ); $html = ''; if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } $id_text = $name; if ( $idtag ) { $id_text = $idtag; } for ($i=0, $n=count( $arr ); $i < $n; $i++ ) { $k = $arr[$i]->$key; $t = $translate ? JText::_( $arr[$i]->$text ) : $arr[$i]->$text; $id = ( isset($arr[$i]->id) ? @$arr[$i]->id : null); $extra = ''; $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : ''; if (is_array( $selected )) { foreach ($selected as $val) { $k2 = is_object( $val ) ? $val->$key : $val; if ($k == $k2) { $extra .= " selected=\"selected\""; break; } } } else { $extra .= ((string)$k == (string)$selected ? " checked=\"checked\"" : ''); } $html .= "\n\t<input type=\"checkbox\" name=\"$name\" id=\"$id_text$k\" value=\"".$k."\"$extra $attribs />"; $html .= "\n\t<label for=\"$id_text$k\">$t</label><br>"; } $html .= "\n"; return $html; }/*end custom checkbox*/
I save the article and everything is normal, the extra field appears as I want.The only problem is when I edit the artcile, the check boxes are not selected, I have to check every option again.If someone can help me to solve this problem I'll be thankfull.
Code:
case 'multipleSelect': $output=JHTML::_('select.genericlist', $defaultValues, 'K2ExtraField_'.$extraField->id.'[]', 'multiple="multiple"', 'value', 'name',$active); break;
I changed with:
Code:
case 'multipleSelect': $output=JHTML::_('select.checkboxlist', $defaultValues, 'K2ExtraField_'.$extraField->id.'[]', '', 'value', 'name',$active); break;
in file libraries/joomla/html/html/select.phpI add:
Code:
/*custom checkbox*/ function checkboxlist( $arr, $name, $attribs = null, $key = 'value', $text = 'text', $selected = null, $idtag = false, $translate = false ) { reset( $arr ); $html = ''; if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } $id_text = $name; if ( $idtag ) { $id_text = $idtag; } for ($i=0, $n=count( $arr ); $i < $n; $i++ ) { $k = $arr[$i]->$key; $t = $translate ? JText::_( $arr[$i]->$text ) : $arr[$i]->$text; $id = ( isset($arr[$i]->id) ? @$arr[$i]->id : null); $extra = ''; $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : ''; if (is_array( $selected )) { foreach ($selected as $val) { $k2 = is_object( $val ) ? $val->$key : $val; if ($k == $k2) { $extra .= " selected=\"selected\""; break; } } } else { $extra .= ((string)$k == (string)$selected ? " checked=\"checked\"" : ''); } $html .= "\n\t<input type=\"checkbox\" name=\"$name\" id=\"$id_text$k\" value=\"".$k."\"$extra $attribs />"; $html .= "\n\t<label for=\"$id_text$k\">$t</label><br>"; } $html .= "\n"; return $html; }/*end custom checkbox*/
I save the article and everything is normal, the extra field appears as I want.The only problem is when I edit the artcile, the check boxes are not selected, I have to check every option again.If someone can help me to solve this problem I'll be thankfull.
Please Log in or Create an account to join the conversation.
- Jordan Ivanov
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 10
14 years 1 month ago #95091
by Jordan Ivanov
Replied by Jordan Ivanov on topic Change multipleSelect with check boxes
I found it:
$extra .= " selected=\"selected\"";
have to be
$extra .= " checked=\"checked\"";
$extra .= " selected=\"selected\"";
have to be
$extra .= " checked=\"checked\"";
Please Log in or Create an account to join the conversation.