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

Conversation

@webmozart
Copy link
Contributor

Bug fix: no
Feature addition: yes
Backwards compatibility break: yes
Symfony2 tests pass: yes
Fixes the following tickets:#5383
Todo: -
License of the code: MIT
Documentation PR:symfony/symfony-docs#2489

The general idea of this PR is to be able to add buttons to forms like so:

$builder->add('clickme','submit');

You can then check in the controller whether the button was clicked:

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

Button-specific validation groups are also supported:

$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 valuefalse in the optionvalidation_groups:

$builder->add('clickme','submit',array('validation_groups' =>false,));

The same can be achieved (already before this PR) by passing an empty array:

$builder->add('clickme','submit',array('validation_groups' =>array(),));

See the linked documentation for more information.

Copy link
Member

Choose a reason for hiding this comment

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

why not<button type="submit"> to be consistent with other buttons ?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are problems with button as a submit in old versions of Internet Explorer.

Choose a reason for hiding this comment

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

@norzechowicz Problems regarding submit buttons are happening only when you don't specify the type of them. There were browsers using "button" as default type whereas others were using "submit".

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I changed it to<button type="submit"> now.

@webmozart
Copy link
ContributorAuthor

Apart from a few missing tests, this PR is pretty much complete now. Feedback welcome.

Copy link
Member

Choose a reason for hiding this comment

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

this is wrong. It is not always a clickable one here

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks, fixed.

@vicb
Copy link
Contributor

vicb commentedJan 2, 2013

@bschussek could be a good nice to have... after the 100+ form issues are tackled !

@webmozart
Copy link
ContributorAuthor

Support for validation groups in submit buttons added.

@webmozart
Copy link
ContributorAuthor

This PR is now complete. I adapted the description above.

Copy link
Member

Choose a reason for hiding this comment

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

You forgot to remove the validation group normalizer here when moving it to the base class

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks, fixed

@marijn
Copy link

@vicb I understand your frustration but I think your comment about the outstanding issues is uncalled for...

Nice addition @bschussek! I've long wondered why buttons are not a part of the framework 👍

@willdurand
Copy link
Contributor

That's nice, really, it's really useful and well-designed, so thanks @bschussek.

But as@vicb there are (a few) issues related to the Form component, and it would be nice to focus on fixing them (IMO).

@sstok
Copy link
Contributor

Changing validation_group depending on the button is great, but I wonder if its a good idea to allow a event (onclick) when a button is clicked. I have some forms that have a 'cancel' button and depending which button is clicked 'submit' or cancel the form is either processed or the user is redirected to another page.

But as binding/bounding a complete form to determine if cancel was clicked could a performance hit, I wonder if its better to keep using the 'old' method for that.

And the 's label, its not uncommon to use HTML (Twitter Bootstrap for instance) knowing that Twig automatically escapes the label.

@webmozart
Copy link
ContributorAuthor

Changing validation_group depending on the button is great, but I wonder if its a good idea to allow a event (onclick) when a button is clicked.

@sstok What do you mean by that? Have you actually looked at the code of this PR?

But as binding/bounding a complete form to determine if cancel was clicked could a performance hit, I wonder if its better to keep using the 'old' method for that.

Performance is not affected (significantly) by this PR.

@sstok
Copy link
Contributor

A was talking in general, in JavaScript you can apply an event handler on a button for when its clicked.
I was wondering if something similar would be useful for the Form component, as choosing the validation_group depending on which button was clicked can be seen as an event.

As an example I have form with a normal submit button for saving and a cancel button which when clicked redirects the user back to the viewing page. Currently I'm checking this with.

if ($this->request->request->has('cancel')) {$isCancelled =true;return$this->onCancel($items) ?:true;}$this->form->bind($this->request);if ($this->form->isValid()) {$this->onConfirm($items);returntrue;}

The form is only binded when its actually gonna be used, but as binding a form even tho I'm only checking if a button was checked could be performance hit (compared to what I'm using now). I was wondering if supporting events when clicked could be useful. It was just a thought.

@webmozart
Copy link
ContributorAuthor

@sstok I see. You can drop your thoughts in#6576 if you like.

@webmozart
Copy link
ContributorAuthor

Postponed to 2.3

@webmozart
Copy link
ContributorAuthor

I rebased this branch on master now, fixed a few issues and wrote the documentation that is linked above. Unless reviews discover problems, this PR is ready for merging.

Copy link
Member

Choose a reason for hiding this comment

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

There is a simpler way:type="{{ type|default('button') }}"

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

Choose a reason for hiding this comment

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

not pushed yet?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

now it is

@webmozart
Copy link
ContributorAuthor

The latest build fail seems to be unrelated to the content of this PR. The build succeeded on 5.4.

@stof
Copy link
Member

@bschussek see#7662

@webmozart
Copy link
ContributorAuthor

Rebased again.

@raziel057
Copy link
Contributor

+1 Usefull to ease the creation of multi step forms. It would be interesting to write a simple usage case sample for multipage forms.

@GromNaN
Copy link
Member

👍 Very useful to detect the clicked button (eg: save / preview).

What is the BC break you mention in the description ?

@stof
Copy link
Member

@GromNaN copied from the changelog:[BC BREAK] setting the option "validation_groups" tofalsenow disables validation instead of assuming group "Default"
@bschussek it should be mentionned in the UPGRADE file at the root as it is a BC break

@webmozart
Copy link
ContributorAuthor

@stof Good point, added this.

fabpot added a commit that referenced this pull requestApr 17, 2013
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
@fabpotfabpot merged commitfaf8d7a intosymfony:masterApr 17, 2013
weaverryan added a commit to symfony/symfony-docs that referenced this pull requestOct 3, 2014
… option (xabbuh)This PR was merged into the 2.3 branch.Discussion----------[Reference] add description for the `validation_groups` option| Q             | A| ------------- | ---| Doc fix?      | no| New docs?     | yes (symfony/symfony#6528)| Applies to    | all| Fixed tickets |#3358Commits-------c41b17c add description for the `validation_groups` option
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

12 participants

@webmozart@vicb@marijn@willdurand@sstok@stof@raziel057@GromNaN@fabpot@Ninir@norberttech@josephzhao

[8]ページ先頭

©2009-2025 Movatter.jp