webdongle, thank you.
This is what i've done.
on my /administrator/components/com_mycomp/models/fields/CategoryCheckBoxes.php
Code: Select all
class JFormFieldCategoryCheckBoxes extends JFormField
{
protected $type = 'checkboxes';
protected function getInput()
{
$db =& JFactory::getDBO();
$query = "SELECT id, title FROM #__copmitips_category WHERE state = 1 ORDER BY title";
$db->setQuery($query);
$categories = $db->loadObjectList();
$var_list ='';
foreach($categories as $category){
$var_list.= '<li><input name="'.$this->name.'[]" type="checkbox" value="'.$category->id.'"><label for="jform_category_id'.$category->id.'">'.$category->title.'</label></li>';
}
return '<fieldset id="jform_category_id" class="checkboxes"><ul>'.$var_list.'</ul></fieldset>';
}
}
On my administrator/components/com_mycomp/models/forms/item.xml
Code: Select all
<field name="category_id" type="CategoryCheckBoxes" required="true" />
then on my administrator/components/com_mycomp/tables/item.php
Code: Select all
public function bind($array, $ignore = '')
{
if (isset($array['category_id']) && is_array($array['category_id'])) {
$array['category_id'] = implode(',', $array['category_id']);
}
return parent::bind($array, $ignore);
}
I can save the value no problem (eg. 1,2,3)
But when I'm editing the form, the checkboxes aren't ticked.
Where do I make it ticked?
I'm stuck... please help.