[Form] made it possible to translate the empty value of Choice fields

This commit is contained in:
Fabien Potencier 2011-06-14 08:33:48 +02:00
parent c364008a3b
commit 2ce3cfad18
3 changed files with 4 additions and 4 deletions

View File

@ -134,7 +134,7 @@
{% else %} {% else %}
<select {{ block('attributes') }}{% if multiple %} multiple="multiple"{% endif %}> <select {{ block('attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
{% if not multiple and empty_value is not none %} {% if not multiple and empty_value is not none %}
<option value="">{{ empty_value }}</option> <option value="">{{ empty_value|trans }}</option>
{% endif %} {% endif %}
{% if preferred_choices|length > 0 %} {% if preferred_choices|length > 0 %}
{% set options = preferred_choices %} {% set options = preferred_choices %}

View File

@ -12,7 +12,7 @@
<?php if ($read_only): ?> disabled="disabled"<?php endif ?> <?php if ($read_only): ?> disabled="disabled"<?php endif ?>
<?php if ($multiple): ?> multiple="multiple"<?php endif ?> <?php if ($multiple): ?> multiple="multiple"<?php endif ?>
> >
<?php if (!$multiple && null !== $empty_value): ?><option value=""><?php echo $empty_value; ?></option><?php endif; ?> <?php if (!$multiple && null !== $empty_value): ?><option value=""><?php echo $view->escape($view['translator']->trans($empty_value)) ?></option><?php endif; ?>
<?php if (count($preferred_choices) > 0): ?> <?php if (count($preferred_choices) > 0): ?>
<?php foreach ($preferred_choices as $choice => $label): ?> <?php foreach ($preferred_choices as $choice => $label): ?>
<?php if ($view['form']->isChoiceGroup($label)): ?> <?php if ($view['form']->isChoiceGroup($label)): ?>

View File

@ -371,7 +371,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'/select '/select
[@name="na&me"] [@name="na&me"]
[ [
./option[@value=""][.=""] ./option[@value=""][.="[trans][/trans]"]
/following-sibling::option[@value="&a"][@selected="selected"][.="Choice&A"] /following-sibling::option[@value="&a"][@selected="selected"][.="Choice&A"]
/following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"] /following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
] ]
@ -394,7 +394,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'/select '/select
[@name="na&me"] [@name="na&me"]
[ [
./option[@value=""][.=""] ./option[@value=""][.="[trans][/trans]"]
/following-sibling::option[@value="&a"][@selected="selected"][.="Choice&A"] /following-sibling::option[@value="&a"][@selected="selected"][.="Choice&A"]
/following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"] /following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
] ]