It looks like you're new here. If you want to get involved, click one of these buttons!
I've read this topic from 2015:
https://forum.getfuelcms.com/discussion/2342/toggle-nested-template-fields
I'm on the develop branch.
With this config in a modules form_fields method:
$fields['workshop'] = [
'type' => 'toggler',
'prefix' => 'toggle_workshop_',
'options' => ['yes' => 'yes', 'no' => 'no'],
'first_option' => 'Is this entry a workshop or not?',
'required' => true
];
$fields['workshop_details'] = [
'display_label' => false,
'repeatable' => true,
'class' => 'toggle toggle_workshop_yes',
'type' => 'template',
'fields' => [
'workshop_title' => [],
'entries' => [
'type' => 'template',
'fields' => [
'time' => [],
'title' => [],
'content' => [
'type' => 'textarea'
]
]
]
]
];
The workshop_details fields are always visible.
If I simplify it by removing the nested 'entries' template type - no change.
If I change the workshop_details field to a simple single text input it does toggle as expected.
Comments
You may need to add that class parameter to each of the fields instead:
Updated it to:
Resulted in all the fields being removed but not the surrounding template. I mean you can still see the grey boxes and "Remove" buttons and drag handles.
I see. The template field is actually not so much a field but a container of fields. There are a couple other options though. There is a
context
andselector
parameter that you can use. Thecontext
parameter is the dom reference of the container element in which to find the specified class (default is.form
). Theselector
parameter specifies what closest element it will look for to hide (default is thetr
). Additionally, there is atemplate
parameter which you can specify view file path with the contents of something like this example which is custom HTML: