Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a158ea

Browse files
committed
merged branch bschussek/issue5383 (PR#6528)
This PR was merged into the master branch.Discussion----------[2.3] [Form] Support buttons in formsBug fix: noFeature addition: yesBackwards compatibility break: yesSymfony2 tests pass: yesFixes the following tickets:#5383Todo: -License of the code: MITDocumentation PR:symfony/symfony-docs#2489The general idea of this PR is to be able to add buttons to forms like so:```php$builder->add('clickme', 'submit');```You can then check in the controller whether the button was clicked:```phpif ($form->get('clickme')->isClicked()) { // do stuff}```Button-specific validation groups are also supported:```php$builder->add('clickme', 'submit', array( 'validation_groups' => 'OnlyClickMe',));```The validation group will then override the one defined in the form if that button is clicked.This PR also introduces the disabling of form validation by passing the value `false` in the option `validation_groups`:```php$builder->add('clickme', 'submit', array( 'validation_groups' => false,));```The same can be achieved (already before this PR) by passing an empty array:```php$builder->add('clickme', 'submit', array( 'validation_groups' => array(),));```See the linked documentation for more information.Commits-------faf8d7a [Form] Added upgrade information about setting "validation_groups" => falsed504732 [Form] Added leading backslashes to @exceptionMessage doc blocksc8afa88 [Form] Removed deprecated code scheduled for removal in 2.336ca056 [Form] Simplified Twig codece29c70 [Form] Fixed incorrect doc comment0bc7129 [Form] Fixed invalid use of FormException600007b [Form] The option "validation_groups" can now be set to false to disable validation. This is identical to setting it to an empty array.277d6df [Form] Fixed concatenation operator CS (see7c47e34)7b07925 [Form] Changed isset() to array_key_exists() to be consistent with ParameterBag7b438a8 [Form] Made submit buttons able to convey validation groupscc2118d [Form] Implemented support for buttons
2 parentsee48912 +faf8d7a commit5a158ea

File tree

62 files changed

+2404
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2404
-395
lines changed

‎UPGRADE-2.3.md‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
UPGRADE FROM 2.2 to 2.3
2+
=======================
3+
4+
###Form
5+
6+
* Although this was not officially supported nor documented, it was possible to
7+
set the option "validation_groups" to false, resulting in the group "Default"
8+
being validated. Now, if you set "validation_groups" to false, the validation
9+
of a form will be skipped (except for a few integrity checks on the form).
10+
11+
If you want to validate a form in group "Default", you should either
12+
explicitly set "validation_groups" to "Default" or alternatively set it to
13+
null.
14+
15+
Before:
16+
17+
```
18+
// equivalent notations for validating in group "Default"
19+
"validation_groups" => null
20+
"validation_groups" => "Default"
21+
"validation_groups" => false
22+
23+
// notation for skipping validation
24+
"validation_groups" => array()
25+
```
26+
27+
After:
28+
29+
```
30+
// equivalent notations for validating in group "Default"
31+
"validation_groups" => null
32+
"validation_groups" => "Default"
33+
34+
// equivalent notations for skipping validation
35+
"validation_groups" => false
36+
"validation_groups" => array()
37+
```

‎src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig‎

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,29 @@
218218
{%endspaceless %}
219219
{%endblockemail_widget %}
220220

221+
{%blockbutton_widget %}
222+
{%spaceless %}
223+
{%iflabelisempty %}
224+
{%setlabel=name|humanize %}
225+
{%endif %}
226+
<buttontype="{{type|default('button') }}" {{block('button_attributes') }}>{{label|trans({},translation_domain) }}</button>
227+
{%endspaceless %}
228+
{%endblockbutton_widget %}
229+
230+
{%blocksubmit_widget %}
231+
{%spaceless %}
232+
{%settype=type|default('submit') %}
233+
{{block('button_widget') }}
234+
{%endspaceless %}
235+
{%endblocksubmit_widget %}
236+
237+
{%blockreset_widget %}
238+
{%spaceless %}
239+
{%settype=type|default('reset') %}
240+
{{block('button_widget') }}
241+
{%endspaceless %}
242+
{%endblockreset_widget %}
243+
221244
{# Labels#}
222245

223246
{%blockform_label %}
@@ -237,6 +260,8 @@
237260
{%endspaceless %}
238261
{%endblockform_label %}
239262

263+
{%blockbutton_label %}{%endblock %}
264+
240265
{# Rows#}
241266

242267
{%blockrepeated_row %}
@@ -259,6 +284,14 @@
259284
{%endspaceless %}
260285
{%endblockform_row %}
261286

287+
{%blockbutton_row %}
288+
{%spaceless %}
289+
<div>
290+
{{ form_widget(form) }}
291+
</div>
292+
{%endspaceless %}
293+
{%endblockbutton_row %}
294+
262295
{%blockhidden_row %}
263296
{{ form_widget(form) }}
264297
{%endblockhidden_row %}
@@ -317,14 +350,9 @@
317350
{%endspaceless %}
318351
{%endblockwidget_container_attributes %}
319352

320-
{# Deprecated in Symfony 2.1, to be removed in 2.3#}
321-
322-
{%blockgeneric_label %}{{block('form_label') }}{%endblock %}
323-
{%blockwidget_choice_options %}{{block('choice_widget_options') }}{%endblock %}
324-
{%blockfield_widget %}{{block('form_widget_simple') }}{%endblock %}
325-
{%blockfield_label %}{{block('form_label') }}{%endblock %}
326-
{%blockfield_row %}{{block('form_row') }}{%endblock %}
327-
{%blockfield_enctype %}{{block('form_enctype') }}{%endblock %}
328-
{%blockfield_errors %}{{block('form_errors') }}{%endblock %}
329-
{%blockfield_rest %}{{block('form_rest') }}{%endblock %}
330-
{%blockfield_rows %}{{block('form_rows') }}{%endblock %}
353+
{%blockbutton_attributes %}
354+
{%spaceless %}
355+
id="{{id }}" name="{{full_name }}"{%ifdisabled %} disabled="disabled"{%endif %}
356+
{%forattrname,attrvalueinattr %}{{attrname }}="{{attrvalue }}" {%endfor %}
357+
{%endspaceless %}
358+
{%endblockbutton_attributes %}

‎src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
{%endspaceless %}
1515
{%endblockform_row %}
1616

17+
{%blockbutton_row %}
18+
{%spaceless %}
19+
<tr>
20+
<td></td>
21+
<tdcolspan="2">
22+
{{ form_widget(form) }}
23+
</td>
24+
</tr>
25+
{%endspaceless %}
26+
{%endblockbutton_row %}
27+
1728
{%blockhidden_row %}
1829
{%spaceless %}
1930
<trstyle="display: none">

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@
140140
<serviceid="form.type.url"class="Symfony\Component\Form\Extension\Core\Type\UrlType">
141141
<tagname="form.type"alias="url" />
142142
</service>
143+
<serviceid="form.type.button"class="Symfony\Component\Form\Extension\Core\Type\ButtonType">
144+
<tagname="form.type"alias="button" />
145+
</service>
146+
<serviceid="form.type.submit"class="Symfony\Component\Form\Extension\Core\Type\SubmitType">
147+
<tagname="form.type"alias="submit" />
148+
</service>
149+
<serviceid="form.type.reset"class="Symfony\Component\Form\Extension\Core\Type\ResetType">
150+
<tagname="form.type"alias="reset" />
151+
</service>
143152

144153
<!-- FormTypeHttpFoundationExtension-->
145154
<serviceid="form.type_extension.form.http_foundation"class="Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension">
@@ -154,5 +163,8 @@
154163
<serviceid="form.type_extension.repeated.validator"class="Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension">
155164
<tagname="form.type_extension"alias="repeated" />
156165
</service>
166+
<serviceid="form.type_extension.submit.validator"class="Symfony\Component\Form\Extension\Validator\Type\SubmitTypeValidatorExtension">
167+
<tagname="form.type_extension"alias="submit" />
168+
</service>
157169
</services>
158170
</container>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
id="<?phpecho$view->escape($id)?>"
2+
name="<?phpecho$view->escape($full_name)?>"
3+
<?phpif ($disabled):?>disabled="disabled"<?phpendif?>
4+
<?phpforeach ($attras$k =>$v):?>
5+
<?phpprintf('%s="%s"',$view->escape($k),$view->escape($v))?>
6+
<?phpendforeach;?>

‎src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/button_label.html.php‎

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<?phpecho$view['form']->widget($form)?>
3+
</div>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?phpif (!$label) {$label =$view['form']->humanize($name); }?>
2+
<button type="<?phpechoisset($type) ?$view->escape($type) :'button'?>"<?phpecho$view['form']->block($form,'button_attributes')?>>
3+
<?php$view->escape($view['translator']->trans($label,array(),$translation_domain))?>
4+
</button>

‎src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/field_enctype.html.php‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/field_errors.html.php‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp