K2 Extra Fields Support Checkbox

Sometime we need MultiSelect with Checkbox if you are using Joomla K2, but K2 missing this functions, now we can hack extrafield.php to realization checkbox in K2.

Just edit the file  /administrator/components/k2/models/extrafield.php and replace these lines:

case 'multipleSelect':
    $output=JHTML::_('select.genericlist', $defaultValues, 'K2ExtraField_'.$extraField->id.'[]', 'multiple="multiple"', 'value', 'name',$active);
break;

with these:

case 'multipleSelect':
    $fid=$extraField->id;
    $field_id = 'K2ExtraField_'.$fid;
    $output='
<div style="display: none;">'; $output.="
<script type="text/javascript">// <![CDATA[
function select_multilist_$fid(t,i) {
                var myselect = document.getElementById('$field_id');
                var status = t.checked;
                myselect[i-1].selected=status;
            }
// ]]></script>
"; $output.=JHTML::_('select.genericlist', $defaultValues, 'K2ExtraField_'.$fid.'[]', 'multiple="multiple"', 'value', 'name',$active); $output.='</div>
 
';
    foreach ($defaultValues as $item){
        $checked = ( in_array($item->value,$active) ) ?  'checked' : '';
        $output.='<input checked="checked" onclick=""select_multilist_'.$fid.'(this,'.$item-" type="checkbox">value.')" > ';
        $output.=$item->name;
        $output.='<br>';
    }
break;

Share this post

Submit to DeliciousSubmit to DiggSubmit to FacebookSubmit to Google BookmarksSubmit to StumbleuponSubmit to TechnoratiSubmit to TwitterSubmit to LinkedIn
Copyright © 2014 JoomlaVisually. All Rights Reserved.
Joomla! is Free Software released under the GNU General Public License.