Skip to content

Commit

Permalink
merged branch acasademont/patch-1 (PR #7678)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

[Form] Remove "value" attribute on empty_value option

Today we faced a very strange issue with the newest Blackberry 10 browser, it was not submitting our forms. Finally we found that in a ```select``` element, if you have a disabled option, it can't have a value or the HTML5 validator will crash and won't submit the form. Of course, setting the ```novalidate``` option for the whole form also solved the issue.

Although I know this must be an issue with the WebKit version the BB10 has, it can easily be solved in symfony with this change. In fact, it does make sense since we already have a disabled option with no value if the ```preferred_choices``` are not empty and a ```separator``` is set

Commits
-------

9e849eb [Form] Remove "value" attribute on empty_value option
  • Loading branch information
fabpot committed Apr 18, 2013
2 parents 47061d7 + 9e849eb commit e51c560
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Expand Up @@ -69,7 +69,7 @@
{% spaceless %}
<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
{% if empty_value is not none %}
<option value=""{% if required %} disabled="disabled"{% if value is empty %} selected="selected"{% endif %}{% endif %}>{{ empty_value|trans({}, translation_domain) }}</option>
<option {% if required %} disabled="disabled"{% if value is empty %} selected="selected"{% endif %}{% else %} value=""{% endif %}>{{ empty_value|trans({}, translation_domain) }}</option>
{% endif %}
{% if preferred_choices|length > 0 %}
{% set options = preferred_choices %}
Expand Down
Expand Up @@ -2,7 +2,7 @@
<?php echo $view['form']->block($form, 'widget_attributes') ?>
<?php if ($multiple): ?> multiple="multiple"<?php endif ?>
>
<?php if (null !== $empty_value): ?><option value=""<?php if ($required):?> disabled="disabled"<?php if (empty($value) && "0" !== $value): ?> selected="selected"<?php endif ?><?php endif?>><?php echo $view->escape($view['translator']->trans($empty_value, array(), $translation_domain)) ?></option><?php endif; ?>
<?php if (null !== $empty_value): ?><option <?php if ($required):?> disabled="disabled"<?php if (empty($value) && "0" !== $value): ?> selected="selected"<?php endif ?><?php else: ?> value=""<?php endif?>><?php echo $view->escape($view['translator']->trans($empty_value, array(), $translation_domain)) ?></option><?php endif; ?>
<?php if (count($preferred_choices) > 0): ?>
<?php echo $view['form']->block($form, 'choice_widget_options', array('choices' => $preferred_choices)) ?>
<?php if (count($choices) > 0 && null !== $separator): ?>
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Expand Up @@ -548,7 +548,7 @@ public function testSingleChoiceRequiredWithEmptyValue()
[@name="name"]
[@required="required"]
[
./option[@value=""][not(@selected)][@disabled][.="[trans]Test&Me[/trans]"]
./option[not(@value)][not(@selected)][@disabled][.="[trans]Test&Me[/trans]"]
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
/following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
]
Expand All @@ -571,7 +571,7 @@ public function testSingleChoiceRequiredWithEmptyValueViaView()
[@name="name"]
[@required="required"]
[
./option[@value=""][not(@selected)][@disabled][.="[trans][/trans]"]
./option[not(@value)][not(@selected)][@disabled][.="[trans][/trans]"]
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
/following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
]
Expand Down

0 comments on commit e51c560

Please sign in to comment.