forked from Kdyby/BootstrapFormRenderer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
@form.latte
99 lines (83 loc) · 3.98 KB
/
@form.latte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{define #form}
{form $form}
{block #errors}
<div n:foreach="$renderer->findErrors() as $error" class="alert alert-error">
<a class="close" data-dismiss="alert">×</a>{$error}
</div>
{/block}
{block #body}
{* controls with group *}
{foreach $renderer->findGroups() as $group}{block #group}
<fieldset>
<legend n:if="$group->label">{$group->label}</legend>
<p n:if="$group->description">{$group->description}</p>
{var $controls = $group->controls}
{if isset($group->template) && $group->template}
{include "$group->template", group => $group,
controls => $controls, submitters => $submitters,
form => $form, _form => $form}
{else}
{block #controls}
{foreach $controls as $control}
{if $renderer->isSubmitButton($control)}
{input $renderer->getControlName($control)}
{if !$renderer->isSubmitButton($iterator->nextValue)}{!="</div>"}{/if}
{?continue}
{/if}
{block #control}
<div id="{$control->htmlId}-pair" n:class="$control->getOption('required')? required, control-group, $control->errors? error">
{var
$name = $renderer->getControlName($control),
$description = $renderer->getControlDescription($control),
$error = $renderer->getControlError($control)
}
{if $controlTemplate = $renderer->getControlTemplate($control)}
<div class="controls">
{include "$controlTemplate", name => $name,
form => $form, _form => $form,
description => $description, error => $error
}
</div>
{elseif $renderer->isButton($control)}
<div class="controls">
{input $name, class => 'btn'}{$error}{$description}
</div>
{elseif $renderer->isCheckbox($control)}
<div class="controls">
{label $name, class => 'checkbox'}{input $name}{$control->label->getText()}{/label}{$error}{$description}
</div>
{elseif $renderer->isRadioList($control)}
{label $name, class => 'control-label' /}
<div class="controls">
{foreach $renderer->getRadioListItems($control) as $item}
{!$item->label->startTag()}
{$item->input}{$item->caption}
{!$item->label->endTag()}
{/foreach}
{$error}{$description}
</div>
{else}
{label $name, class => 'control-label' /}
<div class="controls">
{var $prepend = $control->getOption('input-prepend'), $append = $control->getOption('input-append')}
<div n:class="$prepend? input-prepend, $append? input-append" n:tag-if="$prepend || $append">
{$prepend}{input $name}{$append}
</div>{$error}{$description}
</div>
{/if}
</div>
{/block}
{if $renderer->isSubmitButton($iterator->nextValue)}{!='<div class="form-actions">'}{/if}
{/foreach}
{/block}
{/if}
</fieldset>
{/block}{/foreach}
{* controls without group *}
{include #controls, controls => $renderer->findControls()}
{/block}
{/form}
{/define}
{if !isset($mode)}
{include #form, form => $form, renderer => $renderer}
{/if}