bug #19020 [Form] Fixed collapsed choice attributes (HeahDude)
This PR was merged into the 2.7 branch.
Discussion
----------
[Form] Fixed collapsed choice attributes
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #19016
| License | MIT
| Doc PR | ~
Commits
-------
445dcc8
[Form] Fixed collapsed choice attributes
This commit is contained in:
commit
11f303994c
@ -0,0 +1,9 @@
|
|||||||
|
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>"
|
||||||
|
<?php if ($disabled): ?>disabled="disabled" <?php endif ?>
|
||||||
|
<?php foreach ($choice_attr as $k => $v): ?>
|
||||||
|
<?php if ($v === true): ?>
|
||||||
|
<?php printf('%s="%s" ', $view->escape($k), $view->escape($k)) ?>
|
||||||
|
<?php elseif ($v !== false): ?>
|
||||||
|
<?php printf('%s="%s" ', $view->escape($k), $view->escape($v)) ?>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php endforeach ?>
|
@ -8,6 +8,6 @@ $translatorHelper = $view['translator']; // outside of the loop for performance
|
|||||||
<?php echo $formHelper->block($form, 'choice_widget_options', array('choices' => $choice)) ?>
|
<?php echo $formHelper->block($form, 'choice_widget_options', array('choices' => $choice)) ?>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<option value="<?php echo $view->escape($choice->value) ?>" <?php echo $view['form']->block($form, 'attributes', array('attr' => $choice->attr)) ?><?php if ($is_selected($choice->value, $value)): ?> selected="selected"<?php endif?>><?php echo $view->escape(false !== $choice_translation_domain ? $translatorHelper->trans($choice->label, array(), $choice_translation_domain) : $choice->label) ?></option>
|
<option value="<?php echo $view->escape($choice->value) ?>" <?php echo $formHelper->block($form, 'choice_attributes', array('choice_attr' => $choice->attr)) ?><?php if ($is_selected($choice->value, $value)): ?> selected="selected"<?php endif?>><?php echo $view->escape(false !== $choice_translation_domain ? $translatorHelper->trans($choice->label, array(), $choice_translation_domain) : $choice->label) ?></option>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
|
@ -232,6 +232,68 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSingleChoiceAttributesWithMainAttributes()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||||
|
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||||
|
'choices_as_values' => true,
|
||||||
|
'multiple' => false,
|
||||||
|
'expanded' => false,
|
||||||
|
'attr' => array('class' => 'bar&baz'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'bar&baz')),
|
||||||
|
'/select
|
||||||
|
[@name="name"]
|
||||||
|
[@class="bar&baz form-control"]
|
||||||
|
[not(@required)]
|
||||||
|
[
|
||||||
|
./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
|
||||||
|
/following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
|
||||||
|
]
|
||||||
|
[count(./option)=2]
|
||||||
|
'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSingleExpandedChoiceAttributesWithMainAttributes()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||||
|
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||||
|
'choices_as_values' => true,
|
||||||
|
'multiple' => false,
|
||||||
|
'expanded' => true,
|
||||||
|
'attr' => array('class' => 'bar&baz'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'bar&baz')),
|
||||||
|
'/div
|
||||||
|
[@class="bar&baz"]
|
||||||
|
[
|
||||||
|
./div
|
||||||
|
[@class="radio"]
|
||||||
|
[
|
||||||
|
./label
|
||||||
|
[.=" [trans]Choice&A[/trans]"]
|
||||||
|
[
|
||||||
|
./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
/following-sibling::div
|
||||||
|
[@class="radio"]
|
||||||
|
[
|
||||||
|
./label
|
||||||
|
[.=" [trans]Choice&B[/trans]"]
|
||||||
|
[
|
||||||
|
./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
/following-sibling::input[@type="hidden"][@id="name__token"]
|
||||||
|
]
|
||||||
|
'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSelectWithSizeBiggerThanOneCanBeRequired()
|
public function testSelectWithSizeBiggerThanOneCanBeRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'choice', null, array(
|
$form = $this->factory->createNamed('name', 'choice', null, array(
|
||||||
|
@ -596,6 +596,55 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSingleChoiceAttributesWithMainAttributes()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||||
|
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||||
|
'choices_as_values' => true,
|
||||||
|
'multiple' => false,
|
||||||
|
'expanded' => false,
|
||||||
|
'attr' => array('class' => 'bar&baz'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'bar&baz')),
|
||||||
|
'/select
|
||||||
|
[@name="name"]
|
||||||
|
[@class="bar&baz"]
|
||||||
|
[not(@required)]
|
||||||
|
[
|
||||||
|
./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
|
||||||
|
/following-sibling::option[@value="&b"][not(@class)][not(@selected)][.="[trans]Choice&B[/trans]"]
|
||||||
|
]
|
||||||
|
[count(./option)=2]
|
||||||
|
'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSingleExpandedChoiceAttributesWithMainAttributes()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||||
|
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||||
|
'choices_as_values' => true,
|
||||||
|
'multiple' => false,
|
||||||
|
'expanded' => true,
|
||||||
|
'attr' => array('class' => 'bar&baz'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'bar&baz')),
|
||||||
|
'/div
|
||||||
|
[@class="bar&baz"]
|
||||||
|
[
|
||||||
|
./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
|
||||||
|
/following-sibling::label[@for="name_0"][.="[trans]Choice&A[/trans]"]
|
||||||
|
/following-sibling::input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
|
||||||
|
/following-sibling::label[@for="name_1"][.="[trans]Choice&B[/trans]"]
|
||||||
|
/following-sibling::input[@type="hidden"][@id="name__token"]
|
||||||
|
]
|
||||||
|
[count(./input)=3]
|
||||||
|
'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSingleChoiceWithPreferred()
|
public function testSingleChoiceWithPreferred()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||||
|
Reference in New Issue
Block a user