-
Notifications
You must be signed in to change notification settings - Fork 8
/
withoutFormTheme.html.twig
83 lines (64 loc) · 2.6 KB
/
withoutFormTheme.html.twig
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
{% extends 'FuzAppBundle::layout.html.twig' %}
{% block extra_js %}
<script src="{{ asset('bundles/fuzapp/js/collection/jquery.collection.js') }}"></script>
{% endblock %}
{% block title %}JavaScript options : without the given form theme{% endblock %}
{% block body %}
<h2>{{ block('title') }}</h2>
<p>
To manage complex collections, we should store the collection's field name prefix somewhere in the view
in order to replace descendent prefixes properly. As this is not really natural to get this information from
a view, a form theme is delivered with this jquery plugin. It does the job even if your collection has lots of
descendent collections.
</p>
<p>
But this form theme does nothing more than setting plugin options so if you do not want to use it, that's
up to you:
</p>
<ul>
<li>
<code>name_prefix</code> is mandatory if you do not use the form theme. It should be the prefix of
all descendant field names. Set this information by using:
{% verbatim %}{{ form.values.vars.full_name }}{% endverbatim %}.
</li>
<li>
<code>prototype_name</code> should be the same as inside your form type customization. If you
never given this information, do not set this option (the Symfony2 default value will be used).
</li>
<li>
<code>allow_add</code> should have the same value as the option in your form type. It will enable
or disable the ability to add elements in the collection.
</li>
<li>
<code>allow_remove</code> should have the same value as the option in your form type. It will enable
or disable the ability to delete elements from the collection.
</li>
</ul>
{{
github([
'Controller/OptionsController.php',
'Resources/views/Options/withoutFormTheme.html.twig',
])
}}
{{ form(form) }}
<hr/>
{% for value in formData.values %}
<p>Value : {{ value }}</p>
{% endfor %}
<hr/>
<p>Code used:</p>
<pre>{{ block('script') | e }}</pre>
{% endblock %}
{% block script %}
<script type="text/javascript">
/*
* Please look at the source code by clicking on the withoutFormTheme.html.twig file above
*/
$('.form-collection').collection({
prototype_name: '{{ form.values.vars.prototype.vars.name }}',
allow_add: true,
allow_remove: true,
name_prefix: '{{ form.values.vars.full_name }}'
});
</script>
{% endblock %}