Skip to content

Explained a more simple method of dynamic form handling available since #8827 #2927

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2013

Conversation

Burgov
Copy link
Contributor

@Burgov Burgov commented Aug 24, 2013

symfony/symfony#8827

Q A
Doc fix? yes
New docs? no symfony/symfony#8827
Applies to 2.2.6+
Fixed tickets -

This PR explains the changes in the above mentioned PR.

Also I rewrote the chapter a bit, as it was pretty confusing. In the listener, the client data "event" was used to update the form in PRE_BIND, but in the example this field wasn't even added to the form, making the example broken.

cc @bschussek

@wouterj
Copy link
Member

wouterj commented Aug 24, 2013

could you please include the pull request format in your description?

@@ -412,8 +412,7 @@ sport like this::
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('number_of_people', 'text')
->add('discount_coupon', 'text')
->add('sport', 'entity', array(/* whatever is necessary to fetch the list of sports */))
Copy link
Member

Choose a reason for hiding this comment

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

->add('sport', 'entity', array(...));

@Burgov
Copy link
Contributor Author

Burgov commented Aug 24, 2013

@wouterj I'll apply your changes accordingly. Thanks for the review.

However, I'm up for a git challenge now. I created the branch for #2928 based on the branch for this one, rebased onto 2.3 and added an additional commit for the extra changes. If I rewrite and rebase -i the changes you explained in this PR, how can I cleanly merge them into #2928 without all git hell breaking loose? :)

@wouterj
Copy link
Member

wouterj commented Aug 24, 2013

Well, as said in #2928, you should create that PR after this one is merged. The reason is that you now have 2 commits doing the same thing in 2 branches. That'll confuse GIT.

So, first do this PR. Let it review by @weaverryan and let him merge this one. After that, create a new PR adding new stuff for the 2.3 branch. I know it's a worse workflow, but I didn't found a better one yet.

@Burgov
Copy link
Contributor Author

Burgov commented Aug 24, 2013

@wouterj ah right. I thought that after rebasing, the exact same commit would be in both PR's, but then I forgot that I had to fix merge conflicts in the rebase, which was amended, effectively creating a new commit.

I'll wait for the 2.3 PR then

;
$factory = $builder->getFormFactory();

$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function(FormEvent $event) use($factory){
function(FormEvent $event) use ($factory) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not really necessary to pass the factory here, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the chapter is about dynamic form modification, you're going to need the $factory at some point, even though it isn't in the example. I've changed the example to use it though, to make it more clear

Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily, since Form::add() supports the same interface as FormBuilder::add().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! I thought that was a 2.3 feature but I see it's been there since 2.2. I'll update the examples

@webmozart
Copy link
Contributor

Thank you @Burgov! :)

.. versionadded:: 2.2.6
If you add a POST_BIND listener to a form child, and add new children to the parent
from there, the Form component will detect the new field automatically and maps it
to the client data if it is available.
Copy link
Member

Choose a reason for hiding this comment

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

I think the versionadded directive can be omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure about this?

Copy link
Member

Choose a reason for hiding this comment

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

As far as I understand this was just a bugfix and not a new feature. There are no other places in the docs where we mention specific bugfixes. So I see no reason to do it here.

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, I saw it as a new feature :) You could probably argue for both... I have removed the directive as suggested.

Copy link
Member

Choose a reason for hiding this comment

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

👍

If you have a look at the release notes, you can see that it is listed there as a bugfix, too.

weaverryan added a commit that referenced this pull request Sep 9, 2013
@weaverryan weaverryan merged commit 862df0d into symfony:2.2 Sep 9, 2013
@weaverryan
Copy link
Member

This is great - thanks @Burgov!

I made some small tweaks at sha: b998f86 - there was one actual error, fixed here: b998f86#L0R501. I'm pretty confident in the change, but let me know if I'm wrong :).

Cheers!

weaverryan added a commit that referenced this pull request Sep 13, 2013
weaverryan added a commit that referenced this pull request Sep 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants