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

[2.3] [Form] Support buttons in forms#6528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 11 commits intosymfony:masterfromwebmozart:issue5383
Apr 17, 2013
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
11 commits
Select commitHold shift + click to select a range
cc2118d
[Form] Implemented support for buttons
webmozartDec 31, 2012
7b438a8
[Form] Made submit buttons able to convey validation groups
webmozartJan 2, 2013
7b07925
[Form] Changed isset() to array_key_exists() to be consistent with Pa…
webmozartJan 3, 2013
277d6df
[Form] Fixed concatenation operator CS (see 7c47e34928c39e4797edc8414…
webmozartApr 11, 2013
600007b
[Form] The option "validation_groups" can now be set to false to disa…
webmozartApr 11, 2013
0bc7129
[Form] Fixed invalid use of FormException
webmozartApr 11, 2013
ce29c70
[Form] Fixed incorrect doc comment
webmozartApr 11, 2013
36ca056
[Form] Simplified Twig code
webmozartApr 13, 2013
c8afa88
[Form] Removed deprecated code scheduled for removal in 2.3
webmozartApr 13, 2013
d504732
[Form] Added leading backslashes to @exceptionMessage doc blocks
webmozartApr 13, 2013
faf8d7a
[Form] Added upgrade information about setting "validation_groups" =>…
webmozartApr 15, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletionsUPGRADE-2.3.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
UPGRADE FROM 2.2 to 2.3
=======================

### Form

* Although this was not officially supported nor documented, it was possible to
set the option "validation_groups" to false, resulting in the group "Default"
being validated. Now, if you set "validation_groups" to false, the validation
of a form will be skipped (except for a few integrity checks on the form).

If you want to validate a form in group "Default", you should either
explicitly set "validation_groups" to "Default" or alternatively set it to
null.

Before:

```
// equivalent notations for validating in group "Default"
"validation_groups" => null
"validation_groups" => "Default"
"validation_groups" => false

// notation for skipping validation
"validation_groups" => array()
```

After:

```
// equivalent notations for validating in group "Default"
"validation_groups" => null
"validation_groups" => "Default"

// equivalent notations for skipping validation
"validation_groups" => false
"validation_groups" => array()
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -218,6 +218,29 @@
{% endspaceless %}
{% endblock email_widget %}

{% block button_widget %}
{% spaceless %}
{% if label is empty %}
{% set label = name|humanize %}
{% endif %}
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ label|trans({}, translation_domain) }}</button>
{% endspaceless %}
{% endblock button_widget %}

{% block submit_widget %}
{% spaceless %}
{% set type = type|default('submit') %}
{{ block('button_widget') }}
{% endspaceless %}
{% endblock submit_widget %}

{% block reset_widget %}
{% spaceless %}
{% set type = type|default('reset') %}
{{ block('button_widget') }}
{% endspaceless %}
{% endblock reset_widget %}

{# Labels #}

{% block form_label %}
Expand All@@ -237,6 +260,8 @@
{% endspaceless %}
{% endblock form_label %}

{% block button_label %}{% endblock %}

{# Rows #}

{% block repeated_row %}
Expand All@@ -259,6 +284,14 @@
{% endspaceless %}
{% endblock form_row %}

{% block button_row %}
{% spaceless %}
<div>
{{ form_widget(form) }}
</div>
{% endspaceless %}
{% endblock button_row %}

{% block hidden_row %}
{{ form_widget(form) }}
{% endblock hidden_row %}
Expand DownExpand Up@@ -317,14 +350,9 @@
{% endspaceless %}
{% endblock widget_container_attributes %}

{# Deprecated in Symfony 2.1, to be removed in 2.3 #}

{% block generic_label %}{{ block('form_label') }}{% endblock %}
{% block widget_choice_options %}{{ block('choice_widget_options') }}{% endblock %}
{% block field_widget %}{{ block('form_widget_simple') }}{% endblock %}
{% block field_label %}{{ block('form_label') }}{% endblock %}
{% block field_row %}{{ block('form_row') }}{% endblock %}
{% block field_enctype %}{{ block('form_enctype') }}{% endblock %}
{% block field_errors %}{{ block('form_errors') }}{% endblock %}
{% block field_rest %}{{ block('form_rest') }}{% endblock %}
{% block field_rows %}{{ block('form_rows') }}{% endblock %}
{% block button_attributes %}
{% spaceless %}
id="{{ id }}" name="{{ full_name }}"{% if disabled %} disabled="disabled"{% endif %}
{% for attrname, attrvalue in attr %}{{ attrname }}="{{ attrvalue }}" {% endfor %}
{% endspaceless %}
{% endblock button_attributes %}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,17 @@
{% endspaceless %}
{% endblock form_row %}

{% block button_row %}
{% spaceless %}
<tr>
<td></td>
<td colspan="2">
{{ form_widget(form) }}
</td>
</tr>
{% endspaceless %}
{% endblock button_row %}

{% block hidden_row %}
{% spaceless %}
<tr style="display: none">
Expand Down
12 changes: 12 additions & 0 deletionssrc/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -140,6 +140,15 @@
<service id="form.type.url" class="Symfony\Component\Form\Extension\Core\Type\UrlType">
<tag name="form.type" alias="url" />
</service>
<service id="form.type.button" class="Symfony\Component\Form\Extension\Core\Type\ButtonType">
<tag name="form.type" alias="button" />
</service>
<service id="form.type.submit" class="Symfony\Component\Form\Extension\Core\Type\SubmitType">
<tag name="form.type" alias="submit" />
</service>
<service id="form.type.reset" class="Symfony\Component\Form\Extension\Core\Type\ResetType">
<tag name="form.type" alias="reset" />
</service>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you also need to register the Validator SubmitButtonTypeExtension

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

can I use if $form->get('clickme') == null to check if this exist or not ?

if ($form->get('clickme') != null && $form->get('clickme')->isClicked()) {
// do stuff
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@josephzhao$form->get() will throw an exception in case the child does not exist. This is why we have$form->has()


<!-- FormTypeHttpFoundationExtension -->
<service id="form.type_extension.form.http_foundation" class="Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension">
Expand All@@ -154,5 +163,8 @@
<service id="form.type_extension.repeated.validator" class="Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension">
<tag name="form.type_extension" alias="repeated" />
</service>
<service id="form.type_extension.submit.validator" class="Symfony\Component\Form\Extension\Validator\Type\SubmitTypeValidatorExtension">
<tag name="form.type_extension" alias="submit" />
</service>
</services>
</container>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
id="<?php echo $view->escape($id) ?>"
name="<?php echo $view->escape($full_name) ?>"
<?php if ($disabled): ?>disabled="disabled" <?php endif ?>
<?php foreach ($attr as $k => $v): ?>
<?php printf('%s="%s" ', $view->escape($k), $view->escape($v)) ?>
<?php endforeach; ?>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
<div>
<?php echo $view['form']->widget($form) ?>
</div>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
<?php if (!$label) { $label = $view['form']->humanize($name); } ?>
<button type="<?php echo isset($type) ? $view->escape($type) : 'button' ?>" <?php echo $view['form']->block($form, 'button_attributes') ?>>
<?php $view->escape($view['translator']->trans($label, array(), $translation_domain)) ?>
</button>
View file
Open in desktop

This file was deleted.

View file
Open in desktop

This file was deleted.

View file
Open in desktop

This file was deleted.

View file
Open in desktop

This file was deleted.

View file
Open in desktop

This file was deleted.

View file
Open in desktop

This file was deleted.

View file
Open in desktop

This file was deleted.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
<?php echo $view['form']->block($form, 'button_widget', array('type' => isset($type) ? $type : 'reset')) ?>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
<?php echo $view['form']->block($form, 'button_widget', array('type' => isset($type) ? $type : 'submit')) ?>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
<tr>
<td></td>
<td>
<?php echo $view['form']->widget($form) ?>
</td>
</tr>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,7 +25,7 @@ public function testNormalizeThrowsExceptionWhenFalseIsNotAllowed()
}

/**
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Unrecognized options "foo" under "root"
*/
public function testExceptionThrownOnUnrecognizedChild()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp