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

Appearance settings

[Form] Update UPGRADE-2.3.md to account for #9388 #9804

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

Closed
wants to merge 6 commits into from

Conversation

ureimers
Copy link
Contributor

Added documentation for how to correctly pre-fill a form using the form's data option.
The "old" and also wrong way of doing it broke with Symfony 2.3.7 (with #9388 to be precise) and this short documentation should help others to fix the problem and do it right.

to the data of the object bound to the form (if one was bound).
This was used in some projects to pre-set a form field with optional
initial data as long as there wasn't already data set through a bound object.
Altough this feature is intended, setting the `data` option for a form
Copy link
Contributor

Choose a reason for hiding this comment

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

Although

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although was already used at the beginning paragraph of the file so I wanted to spice up the wording. Maybe "While" would be o.k. too?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

The fact that not setting the `data` option doesn't lock the form can be taken out of the description which states that *if* the `data` option is set the data will be locked automatically (so the opposite must be happening if it isn't).
$builder->add('field', 'text', array(
'data' => $options['default_data'] ?: null,
));
$builder->get('field')->setDataLocked(false);
Copy link
Member

Choose a reason for hiding this comment

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

The other way is to omit the data option entirely when you don't have a default data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had that in there in the first place (ureimers@1c74898) but Luis mentioned that it would be better to be explicit and I agreed so I removed that alternative. I honestly starting to don't know which way is the best here and if I should show them both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What users want to accomplish is set a value that is always used if there is no data bound and never used if there is.
In other words: They want to implement a default_value option.
Before 2.3.7 they where able to accomplish that with the above mentioned code under Before:.
So to be able to do that >=2.3.7 they need to change their code like I mentioned in After:.
I think as a guideline to how to accomplish something in 2.3 you where able to do prior 2.3 this should suffice.

Copy link
Member

Choose a reason for hiding this comment

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

IMO, omitting the data option is a better implementation than passing the data option and then modifying the builder to tell it to ignore it

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @stof.

@webmozart
Copy link
Contributor

Sent PR ureimers#1 to update the wording and before/after example.

[Form] Fixed wording in the UPGRADE file
fabpot added a commit that referenced this pull request Jan 6, 2014
This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes #9804).

Discussion
----------

[Form] Update UPGRADE-2.3.md to account for #9388

Added documentation for how to correctly pre-fill a form using the form's `data` option.
The "old" and also wrong way of doing it broke with Symfony 2.3.7 (with #9388 to be precise) and this short documentation should help others to fix the problem and do it right.

Commits
-------

5e06535 [Form] Update UPGRADE-2.3.md to account for #9388
@fabpot fabpot closed this Jan 6, 2014
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.