Using fieldset in the CMS
I would like to try out the fieldset option in the CMS on a page where I have a large number of fields. At the top of the form I have a 'mode' radio button set to select the 'mode' of the form. Options are 'basic', 'intermediate', 'advanced'
I want to place specific form fields in fieldsets corresponding to the mode selected by the user.
In the 1.0 userguide you have the following:
This field type groups fields together. If the form is rendered in the CMS, you can assign the 'class' parameter the value of 'tab' or "collapsible" and the fields will grouped under tabs or collapsible headers respectively.Really wanted to see the tabs in action in the CMS. What I really wanted to do is only show the fields that correspond to the chosen 'mode' or tab and hide the other fields. Do you have an example of how fieldset types are opened and closed around groups of fields in the form_fields() method of the model?
I've tried this based on what I see in your fuel_assets_model.php file but it's placing the tabs at the bottom of the page in the CMS and no fields are contained in the tabs.
Here's a link to a dropbox screenshot of the CMS for this model:
https://dl.dropboxusercontent.com/u/7699254/MPG/Screen Shot 2013-11-02 at 11.23.51 AM.pngHere's the form_fields section of my model (abbreviated)
function form_fields($values = array())
{
$fields = parent::form_fields($values);
//Section for Basic
$fields['basic'] = array('type' => 'fieldset', 'class' => 'tab');
// 3 field definitions are in here
//Section for Intermediate
//CSS Section
$fields['intermediate'] = array('type' => 'fieldset', 'class' => 'tab');
// a bunch of field definitions here
//Section for Advanced
$fields['advanced'] = array('type' => 'fieldset', 'class' => 'tab');
// a bunch field definitions here
return $fields;
}
Any idea what I might be doing wrong? Can't wait to get this to work in Fuel! Thanks in advance.
Comments
//Section for Basic $fields['basic'] = array('type' => 'fieldset', 'class' => 'tab', 'order' => 0);
$fields = parent::form_fields($values);
and the tabs do appear at the top (btw, the order => 0 tab is created as #fieldset3 rather than first).But, the fieldsets are being assembled around the fields based on the order of the fields in the database no matter how I order the data fields themselves. I tried using no order designations, ordering overall and ordering as a subset of the fieldset order numbers.
There's nothing under the first tab (#fieldset0 which is actually 'order' => 1), the second tab (#fieldset1 - 'order' => 2) only contains the 3rd field from the db table (the first 2 are id's and hidden), the 3rd tab (#fieldset2 - 'order' => 3) contains all the rest of the db table's fields in the same order as that of the table, and the 4th tab contains all the fields that are 'type' => 'section' with no actual data fields.
If I switch this:
$fields = parent::form_fields($values); $CI =& get_instance();
back to this:$CI =& get_instance(); $fields = array();
AND remove all ordering of the fields (doesn't work at all with field ordering) It all works again. Will I lose anything by using the latter to define $fields at the top of form_fields()Any idea why I might be having these issues?
// set order $fields['general_tab'] = array('type' => 'fieldset', 'label' => 'General', 'class' => 'tab', 'order' => 1); $fields['advanced_tab'] = array('type' => 'fieldset', 'label' => 'Advanced', 'class' => 'tab', 'order' => 5); $order = array( 'general_tab', 'group_id', 'label', 'location', 'nav_key', 'parent_id', 'published', 'language', 'advanced_tab', 'precedence', 'attributes', 'selected', 'hidden' ); foreach($order as $key => $val) { $fields[$val]['order'] = $key + 1; }