Skip to content
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

[WIP] [2.7+] explicit differences between 'data' & 'empty_data' options in FormType #6265

Closed
wants to merge 5 commits into from

Conversation

HeahDude
Copy link
Contributor

It seems to be some confusion between two options data and empty_data` in regard of these two old symfony issues I read yesterday (symfony/symfony#14579, symfony/symfony#16530).

Probably because of their name and the fact that they both are some kind of "placeholder" in different step of the form cycle.

@jakzal advise me to open a PR here for that matter.

IMO both of their descriptions are already pretty clear.

You can see in this PR an attempt to explicit and focus on the context in which they are requested.

Any idea or suggestions are welcome.

@@ -15,5 +15,5 @@ just an individual field, you can set it in the data option::
.. note::

The default values for form fields are taken directly from the underlying
data structure (e.g. an entity or an array). The ``data`` option overrides
this default value.
data structure matching the field name with a property of an object or a
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 tried to centralize structure references in the note.

@@ -10,11 +10,12 @@ empty_data
DEFAULT_PLACEHOLDER

This option determines what value the field will return when the submitted
value is empty.
value is empty. It does not set an initial value if none is provided when
the form is rendered in a view (see ``data`` or ``placeholder`` options).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nice to link the options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please can some one tell me how can I do it?

@HeahDude
Copy link
Contributor Author

Updated. closes #6340.

@HeahDude
Copy link
Contributor Author

Any reviews here? There are many confusions about this.

data structure (e.g. an entity or an array). The ``data`` option overrides
this default value.
data structure matching the field's name with a property of an object or a
key of an array. The ``data`` option overrides this default value.
Copy link
Member

Choose a reason for hiding this comment

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

You should make it clearer than overriding the default value like this will cause issues if you are using the form to edit an object rather than to create it, as the form value will still be filled from data even if the underlying data structure also has a value for it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for this heads-up!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stof done in the sentence below

@HeahDude HeahDude force-pushed the form-empty_data-option branch from e3894be to 133a77c Compare May 21, 2016 11:25
@HeahDude
Copy link
Contributor Author

HeahDude commented May 21, 2016

Ok there is quite some work here before it's finished.

I propose to override the empty_data option globally for:

  • choice types (used for choice, locale, country, currency, timezone with some expanded examples info in choice type about multiple and an update with choice_name option in 2.7+),
  • time types (birthday, date, date time, time), note that actually the option is missing in these types and there is [3.0] [Form] DateType ignores "empty_data" option symfony#4715,
  • one specific about entity type (about string ids),
  • suggestions ?

with dedicated example. It would be easier with a second marker like it's currently done with DEFAULT_PLACEHOLDER.

What do you think?

@xabbuh
Copy link
Member

xabbuh commented May 21, 2016

@HeahDude sounds like a good plan to me

@HeahDude
Copy link
Contributor Author

Ref symfony/symfony#19165

@HeahDude HeahDude changed the title [WIP] [2.3+] explicit differences between 'data' & 'empty_data' options in FormType [WIP] [2.7+] explicit differences between 'data' & 'empty_data' options in FormType Jul 2, 2016
@xabbuh
Copy link
Member

xabbuh commented Nov 10, 2016

@HeahDude Do you think you may find some time to finish this one? :)

@HeahDude
Copy link
Contributor Author

It's hard to find some time these days, but sure I will :) In the meanwhile if someone wants to take over this PR, let it be!

@wouterj
Copy link
Member

wouterj commented Apr 15, 2017

Closing in favor of #7802

@wouterj wouterj closed this Apr 15, 2017
xabbuh added a commit that referenced this pull request May 4, 2017
…s more visisble (HeahDude, wouterj, javiereguiluz)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Make difference between data and empty_data options more visisble

Finishes #6265
Fixes #7299, #7596

Commits
-------

64e3984 Fixed a minor typo
df9b878 Fixed a minor typo
f375489 Better explain empty_data values
d552ea3 Readd mixed type for empty_data, it can be string, array or object
188f0ab Tried to write the important points more explicitly
5f3813d Updated the example add added a caution
4fd2d96 Addressed @stof's comment
242941a improved accuracy
67c93b6 fix typo
87b3542 explicit differences between 'data' & 'empty_data' in FormType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants