Skip to content

Commit

Permalink
[Form] empty_value should not be selectable in choice field if the fi…
Browse files Browse the repository at this point in the history
…eld is required
  • Loading branch information
nicam committed Dec 16, 2012
1 parent fefa9ed commit a9c27fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 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="">{{ empty_value|trans({}, translation_domain) }}</option>
<option value="" disabled="disabled"{% if value is empty %} selected="selected"{% 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 echo $view->escape($view['translator']->trans($empty_value, array(), $translation_domain)) ?></option><?php endif; ?>
<?php if (null !== $empty_value): ?><option value="" disabled="disabled"<?php if (empty($value) && "0" !== $value): ?> selected="selected"<?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
40 changes: 20 additions & 20 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Expand Up @@ -524,7 +524,7 @@ public function testSingleChoiceWithNonRequiredEmptyValue()
[@name="name"]
[not(@required)]
[
./option[@value=""][not(@selected)][.="[trans]Select&Anything&Not&Me[/trans]"]
./option[@value=""][not(@selected)][@disabled][.="[trans]Select&Anything&Not&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 @@ -548,7 +548,7 @@ public function testSingleChoiceRequiredWithEmptyValue()
[@name="name"]
[@required="required"]
[
./option[@value=""][.="[trans]Test&Me[/trans]"]
./option[@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=""][.="[trans][/trans]"]
./option[@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 Expand Up @@ -790,7 +790,7 @@ public function testCountryWithEmptyValue()
$this->assertWidgetMatchesXpath($form->createView(), array(),
'/select
[@name="name"]
[./option[@value=""][not(@selected)][.="[trans]Select&Country[/trans]"]]
[./option[@value=""][not(@selected)][@disabled][.="[trans]Select&Country[/trans]"]]
[./option[@value="AT"][@selected="selected"][.="[trans]Austria[/trans]"]]
[count(./option)>201]
'
Expand Down Expand Up @@ -852,13 +852,13 @@ public function testDateTimeWithEmptyValueGlobal()
[
./select
[@id="name_date_month"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_date_day"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_date_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
]
/following-sibling::div
[@id="name_time"]
Expand Down Expand Up @@ -907,10 +907,10 @@ public function testDateTimeWithEmptyValueOnTime()
[
./select
[@id="name_time_hour"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][not(@selected)][@disabled][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_time_minute"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][not(@selected)][@disabled][.="[trans]Change&Me[/trans]"]]
]
]
[count(.//select)=5]
Expand Down Expand Up @@ -1063,13 +1063,13 @@ public function testDateChoiceWithEmptyValueGlobal()
[
./select
[@id="name_month"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_day"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
]
[count(./select)=3]
'
Expand All @@ -1096,7 +1096,7 @@ public function testDateChoiceWithEmptyValueOnYear()
[./option[@value="1"]]
/following-sibling::select
[@id="name_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
]
[count(./select)=3]
'
Expand Down Expand Up @@ -1195,15 +1195,15 @@ public function testBirthDayWithEmptyValue()
[
./select
[@id="name_month"]
[./option[@value=""][.="[trans][/trans]"]]
[./option[@value=""][not(@selected)][@disabled][.="[trans][/trans]"]]
[./option[@value="1"][@selected="selected"]]
/following-sibling::select
[@id="name_day"]
[./option[@value=""][.="[trans][/trans]"]]
[./option[@value=""][not(@selected)][@disabled][.="[trans][/trans]"]]
[./option[@value="1"][@selected="selected"]]
/following-sibling::select
[@id="name_year"]
[./option[@value=""][.="[trans][/trans]"]]
[./option[@value=""][not(@selected)][@disabled][.="[trans][/trans]"]]
[./option[@value="1950"][@selected="selected"]]
]
[count(./select)=3]
Expand Down Expand Up @@ -1635,11 +1635,11 @@ public function testTimeWithEmptyValueGlobal()
[
./select
[@id="name_hour"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
[count(./option)>24]
/following-sibling::select
[@id="name_minute"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
[count(./option)>60]
]
[count(./select)=2]
Expand All @@ -1660,7 +1660,7 @@ public function testTimeWithEmptyValueOnYear()
[
./select
[@id="name_hour"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Change&Me[/trans]"]]
[count(./option)>24]
/following-sibling::select
[@id="name_minute"]
Expand Down Expand Up @@ -1710,7 +1710,7 @@ public function testTimezoneWithEmptyValue()

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/select
[./option[@value=""][.="[trans]Select&Timezone[/trans]"]]
[./option[@value=""][@selected][@disabled][.="[trans]Select&Timezone[/trans]"]]
[count(./optgroup)>10]
[count(.//option)>201]
'
Expand Down

0 comments on commit a9c27fb

Please sign in to comment.