8000 [Form] Renamed the option "empty_value" to "placeholder" by norberttech · Pull Request #6475 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Renamed the option "empty_value" to "placeholder" #6475

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 3 commits into from

Conversation

norberttech
Copy link
Contributor

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #5791
License of the code: MIT

This PR adds placeholder option to types represented in html by input element and rename empty_value option into placeholder in types represented in html by select.

@wiistriker
Copy link

i think "placeholder" may confuse some developers. I think "empty_value" reflect it meaning better, than "placeholder".

There is "placeholder" in html forms already http://www.w3schools.com/html5/att_input_placeholder.asp

@Tobion
Copy link
Contributor
Tobion commented Dec 24, 2012

@wiistriker this is exactly what this PR is about...

@wiistriker
Copy link

@Tobion if i understand it right, this PR affect and choice field. https://github.com/symfony/symfony/pull/6475/files#L1L108 i think for Choice there is better use empty_value than placeholder. For other fields i agree, it should be placholder if it really work with placeholder html attr.

@@ -165,21 +165,26 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
return '';
};

$emptyValue = function (Options $options) {
$placeholderValue = function (Options $options) {
return $options['required'] ? null : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

The value of the deprecated option should take precedence here:

return null !== $options['empty_value'] ? $options['empty_value'] : ($options['required'] ? null : '');

@webmozart
Copy link
Contributor

@wiistriker Please read #5791 for more information.

@norberttech
Copy link
Contributor Author

@bschussek Are you sure about moving placeholder option from TextType to FormType? As I said before it will add placeholder option also into types that don't need it, like checkbox.

@webmozart
Copy link
Contributor

@norzechowicz Unfortunately I am not. Don't you feel that this is better than duplicating the placeholder logic in all the other types that need it?

@webmozart
Copy link
Contributor

As far as I see now, checkboxes and radio buttons would be the only types that would unnecessarily have this attribute. Can you think of any other types?

@norberttech
Copy link
Contributor Author

Yes, you are right about duplicating but every type that not inherits placeholder option from TextTyp probably needs different logic for it. First example is Choictype. Placeholder option is required in that case but not as a attribute and that might be hard to achieve after moving placeholder option to FormTyp.

@norberttech
Copy link
Contributor Author

@bschussek I tried to move placeholder logic into FormType but this causes a lot of problems in widget_attributes block. Do you have any other suggestion what can be done to prevent duplicating logic?

id="{{ id }}" name="{{ full_name }}"{% if read_only %} readonly="readonly"{% endif %}{% if disabled %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
{% for attrname, attrvalue in attr %}{% if attrname in ['placeholder', 'title'] %}{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}" {% else %}{{ attrname }}="{{ attrvalue }}" {% endif %}{% endfor %}
id="{{ id }}" name="{{ full_name }}"{% if read_only %} readonly="readonly"{% endif %}{% if disabled %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}{% if placeholder is defined %} placeholder="{{ placeholder|trans({}, translation_domain) }}"{% endif %}
{% for attrname, attrvalue in attr %}{% if attrname in ['title'] %}{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}" {% else %}{{ attrname }}="{{ attrvalue }}" {% endif %}{% endfor %}
Copy link
Contributor

Choose a reason for hiding this comment

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

if 'title' == attrname

@webmozart
Copy link
Contributor

Currently I don't. I need to look into this in more detail once 2.2 is released.

@webmozart
Copy link
Contributor

ref #9177

@webmozart
Copy link
Contributor

Replaced by #12003.

@webmozart webmozart closed this Sep 23, 2014
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
0