e107sk.com

Multicheckbox field

How to set multicheck field
on Saturday 07 December 2019
comments: 0

Multicheck field in admin UI


Inspiration (or core check): admin/newspost.php and field: news_render_type

Example:

 
'blank_compatibility' 		 
=> array( 
	'title' => "Checkbox check", 
	'type' => 'dropdown', 
	'data'=>'str', 
	'inline'=>true, 
	'readParms'=>array('type'=>'checkboxes'), 
	'writeParms'=>array('multiple'=>'1', 'optArray' => array('0'=>'first option', '1' => 'second option')),<br />
	'width' => 'auto', 
	'thclass' => 'left', 
	'class' => 'left', 
	'nosort' => false, 
),<br />


Explanation:
- 'data' - Data Type: string (it saves values separated by comma)
- 'type' - news uses dropdown, type checkbox is only for one value ( (0 or 1 is returned)

Inline editing:

 
'inline'=>true, 
'readParms'=>array('type'=>'checkboxes'), 

type checkboxes allows multiselect

117d9c2965fc

Options:
'multiple' - you can select more than one option

'optArray' - list of options. It's just example, you can fill it in init() method from database values. If you don't use keys, they will be 0,1,2..., but if you use keys, those ones will be used.

Example how to get data from related table:

$parents = e107::getDb()->retrieve("property_location", "*", "WHERE parent_id = 0", true);
            $parent_item[0] = "None selected";
 
            foreach($parents as $parent) {
              $parent_item[$parent['id']] = $parent['title'];
            }
	        $this->fields['parent_id']['writeParms']['optArray'] =  $parent_item;

0 Comments

Other links

Follow us