Skip to content

Commit 6708dba

Browse files
committed
Added ability to disable form tabs closes #951
1 parent 850a4ea commit 6708dba

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

Form/Extension/TabbedFormTypeExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
100100
'label' => $child->vars['label'],
101101
'icon' => $child->vars['icon'],
102102
'active' => false,
103+
'disabled' => $child->vars['disabled'],
103104
'translation_domain' => $child->vars['translation_domain'],
104105
);
105106

Form/Type/TabType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
3131
$resolver->setDefaults(array(
3232
'icon' => null,
3333
'error_icon' => 'remove-sign',
34+
'disabled' => false,
3435
));
3536
}
3637

@@ -42,6 +43,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
4243
$view->vars['valid'] = $valid = !$form->isSubmitted() || $form->isValid();
4344
$view->vars['icon'] = $valid ? $options['icon'] : $options['error_icon'];
4445
$view->vars['tab_active'] = false;
46+
$view->vars['disabled'] = $options['disabled'];
4547

4648
$view->parent->vars['tabbed'] = true;
4749
}

Resources/views/Form/fields.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@
128128
{% spaceless %}
129129
<ul class="{{ form.vars.attr.class }}">
130130
{% for tab in form.vars.tabs %}
131-
<li{% if tab.active %} class="active"{% endif %}>
131+
{% set class = (tab.active ? 'active ' : '') ~ (tab.disabled ? 'disabled' : '') %}
132+
<li{% if class|trim is not empty %} class="{{ class }}"{% endif %}>
132133
<a data-toggle="tab" href="#{{ tab.id }}">
133134
{% if tab.icon %}{{ mopa_bootstrap_icon(tab.icon) }}{% endif %}
134135
{{ tab.label|trans({}, tab.translation_domain) }}

0 commit comments

Comments
 (0)