diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index e91409574b2e4..3d9b6c28210f6 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -243,6 +243,7 @@ public function testSetDataMultipleNonExpandedNull() public function testSubmitSingleExpandedNull() { $field = $this->factory->createNamed('name', 'entity', null, array( + 'required' => true, 'multiple' => false, 'expanded' => true, 'em' => 'default', @@ -257,6 +258,7 @@ public function testSubmitSingleExpandedNull() public function testSubmitSingleNonExpandedNull() { $field = $this->factory->createNamed('name', 'entity', null, array( + 'required' => true, 'multiple' => false, 'expanded' => false, 'em' => 'default', @@ -271,6 +273,7 @@ public function testSubmitSingleNonExpandedNull() public function testSubmitMultipleNull() { $field = $this->factory->createNamed('name', 'entity', null, array( + 'required' => true, 'multiple' => true, 'em' => 'default', 'class' => self::SINGLE_IDENT_CLASS, diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 4381726126d48..a61f40753efce 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * added "html5" option to Date, Time and DateTimeFormType to be able to enable/disable HTML5 input date when widget option is "single_text" + * the default value of the "required" option was changed to false 2.5.0 ------ diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 28c991e96b71c..7c77d93891e62 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -268,6 +268,7 @@ private function addSubForms(FormBuilderInterface $builder, array $choiceViews, $choiceOpts = array( 'value' => $choiceView->value, 'label' => $choiceView->label, + 'required' => $options['required'], 'translation_domain' => $options['translation_domain'], ); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index 924e1263a71c0..9341170aa5c3b 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -190,7 +190,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'data_class' => $dataClass, 'empty_data' => $emptyData, 'trim' => true, - 'required' => true, + 'required' => false, 'read_only' => false, 'max_length' => null, 'pattern' => null, diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php index 7b38fc49abe79..77b244b691ba2 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php @@ -84,18 +84,18 @@ public function buildForm(FormBuilderInterface $builder, array $options) $secondOptions['choices'] = $seconds; $secondOptions['placeholder'] = $options['placeholder']['second']; } + } - // Append generic carry-along options - foreach (array('required', 'translation_domain') as $passOpt) { - $hourOptions[$passOpt] = $options[$passOpt]; + // Append generic carry-along options + foreach (array('required', 'translation_domain') as $passOpt) { + $hourOptions[$passOpt] = $options[$passOpt]; - if ($options['with_minutes']) { - $minuteOptions[$passOpt] = $options[$passOpt]; - } + if ($options['with_minutes']) { + $minuteOptions[$passOpt] = $options[$passOpt]; + } - if ($options['with_seconds']) { - $secondOptions[$passOpt] = $options[$passOpt]; - } + if ($options['with_seconds']) { + $secondOptions[$passOpt] = $options[$passOpt]; } } diff --git a/src/Symfony/Component/Form/FormConfigBuilder.php b/src/Symfony/Component/Form/FormConfigBuilder.php index 2bc7c2ec220ff..fd86a792c72a3 100644 --- a/src/Symfony/Component/Form/FormConfigBuilder.php +++ b/src/Symfony/Component/Form/FormConfigBuilder.php @@ -110,7 +110,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface /** * @var bool */ - private $required = true; + private $required = false; /** * @var bool diff --git a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php index 1f151a8c6d142..19a00b0549046 100644 --- a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php @@ -48,6 +48,25 @@ public function testRowOverrideVariables() $this->assertMatchesXpath($html, '/div + [ + ./label[@for="name"][@class="my&label&class"][.="[trans]foo&bar[/trans]"] + /following-sibling::input[@id="name"][@class="my&class"] + ] +' + ); + } + + public function testRowOverrideVariablesRequiredField() + { + $view = $this->factory->createNamed('name', 'text', null, array('required' => true))->createView(); + $html = $this->renderRow($view, array( + 'attr' => array('class' => 'my&class'), + 'label' => 'foo&bar', + 'label_attr' => array('class' => 'my&label&class'), + )); + + $this->assertMatchesXpath($html, +'/div [ ./label[@for="name"][@class="my&label&class required"][.="[trans]foo&bar[/trans]"] /following-sibling::input[@id="name"][@class="my&class"] @@ -525,7 +544,7 @@ public function testRepeatedWithCustomOptions() { $form = $this->factory->createNamed('name', 'repeated', null, array( // the global required value cannot be overridden - 'first_options' => array('label' => 'Test', 'required' => false), + 'first_options' => array('label' => 'Test', 'required' => true), 'second_options' => array('label' => 'Test2'), )); @@ -535,12 +554,12 @@ public function testRepeatedWithCustomOptions() ./div [ ./label[@for="name_first"][.="[trans]Test[/trans]"] - /following-sibling::input[@type="text"][@id="name_first"][@required="required"] + /following-sibling::input[@type="text"][@id="name_first"] ] /following-sibling::div [ ./label[@for="name_second"][.="[trans]Test2[/trans]"] - /following-sibling::input[@type="text"][@id="name_second"][@required="required"] + /following-sibling::input[@type="text"][@id="name_second"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 4755e208e9a51..c8dab5bed51f0 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -152,15 +152,18 @@ public function testLabel() ); } - public function testLabelOnForm() + public function testLabelForRequiredField() { - $form = $this->factory->createNamed('name', 'date'); + $form = $this->factory->createNamed('name', 'text', null, array( + 'required' => true, + )); $view = $form->createView(); $this->renderWidget($view, array('label' => 'foo')); $html = $this->renderLabel($view); $this->assertMatchesXpath($html, '/label + [@for="name"] [@class="required"] [.="[trans]Name[/trans]"] ' @@ -222,7 +225,6 @@ public function testLabelDoesNotRenderFieldAttributes() $this->assertMatchesXpath($html, '/label [@for="name"] - [@class="required"] ' ); } @@ -238,6 +240,25 @@ public function testLabelWithCustomAttributesPassedDirectly() $this->assertMatchesXpath($html, '/label + [@for="name"] + [@class="my&class"] +' + ); + } + + public function testRequiredLabelWithCustomClass() + { + $form = $this->factory->createNamed('name', 'text', null, array( + 'required' => true, + )); + $html = $this->renderLabel($form->createView(), null, array( + 'label_attr' => array( + 'class' => 'my&class', + ), + )); + + $this->assertMatchesXpath($html, +'/label [@for="name"] [@class="my&class required"] ' @@ -256,7 +277,7 @@ public function testLabelWithCustomTextAndCustomAttributesPassedDirectly() $this->assertMatchesXpath($html, '/label [@for="name"] - [@class="my&class required"] + [@class="my&class"] [.="[trans]Custom label[/trans]"] ' ); @@ -277,7 +298,7 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly $this->assertMatchesXpath($html, '/label [@for="name"] - [@class="my&class required"] + [@class="my&class"] [.="[trans]Custom label[/trans]"] ' ); @@ -366,6 +387,7 @@ public function testSingleChoice() { $form = $this->factory->createNamed('name', 'choice', '&a', array( 'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'), + 'required' => true, 'multiple' => false, 'expanded' => false, )); @@ -400,6 +422,7 @@ public function testSingleChoiceWithPreferred() $form = $this->factory->createNamed('name', 'choice', '&a', array( 'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'), 'preferred_choices' => array('&b'), + 'required' => true, 'multiple' => false, 'expanded' => false, )); @@ -423,6 +446,7 @@ public function testSingleChoiceWithPreferredAndNoSeparator() $form = $this->factory->createNamed('name', 'choice', '&a', array( 'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'), 'preferred_choices' => array('&b'), + 'required' => true, 'multiple' => false, 'expanded' => false, )); @@ -445,6 +469,7 @@ public function testSingleChoiceWithPreferredAndBlankSeparator() $form = $this->factory->createNamed('name', 'choice', '&a', array( 'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'), 'preferred_choices' => array('&b'), + 'required' => true, 'multiple' => false, 'expanded' => false, )); @@ -468,6 +493,7 @@ public function testChoiceWithOnlyPreferred() $form = $this->factory->createNamed('name', 'choice', '&a', array( 'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'), 'preferred_choices' => array('&a', '&b'), + 'required' => true, 'multiple' => false, 'expanded' => false, )); @@ -703,6 +729,7 @@ public function testSingleChoiceExpanded() { $form = $this->factory->createNamed('name', 'choice', '&a', array( 'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'), + 'required' => true, 'multiple' => false, 'expanded' => true, )); @@ -725,6 +752,7 @@ public function testSingleChoiceExpandedWithPlaceholder() { $form = $this->factory->createNamed('name', 'choice', '&a', array( 'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'), + 'required' => true, 'multiple' => false, 'expanded' => true, 'placeholder' => 'Test&Me', @@ -750,6 +778,7 @@ public function testSingleChoiceExpandedWithBooleanValue() { $form = $this->factory->createNamed('name', 'choice', true, array( 'choices' => array('1' => 'Choice&A', '0' => 'Choice&B'), + 'required' => true, 'multiple' => false, 'expanded' => true, )); @@ -772,9 +801,9 @@ public function testMultipleChoiceExpanded() { $form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array( 'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B', '&c' => 'Choice&C'), + 'required' => true, 'multiple' => true, 'expanded' => true, - 'required' => true, )); $this->assertWidgetMatchesXpath($form->createView(), array(), @@ -1611,6 +1640,35 @@ public function testTimeText() $this->assertWidgetMatchesXpath($form->createView(), array(), '/div + [ + ./input + [@type="text"] + [@id="name_hour"] + [@name="name[hour]"] + [@value="04"] + [@size="1"] + /following-sibling::input + [@type="text"] + [@id="name_minute"] + [@name="name[minute]"] + [@value="05"] + [@size="1"] + ] + [count(./input)=2] +' + ); + } + + public function testTimeTextRequired() + { + $form = $this->factory->createNamed('name', 'time', '04:05:06', array( + 'input' => 'string', + 'widget' => 'text', + 'required' => true, + )); + + $this->assertWidgetMatchesXpath($form->createView(), array(), +'/div [ ./input [@type="text"] @@ -1918,7 +1976,7 @@ public function testWidgetAttributeNameRepeatedIfTrue() $html = $this->renderWidget($form->createView()); // foo="foo" - $this->assertSame('', $html); + $this->assertSame('', $html); } public function testWidgetAttributeHiddenIfFalse() diff --git a/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php index 34153a9f1e4c1..f62fdec17224c 100644 --- a/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php @@ -401,7 +401,7 @@ public function testRepeatedWithCustomOptions() { $form = $this->factory->createNamed('name', 'repeated', 'foobar', array( 'type' => 'password', - 'first_options' => array('label' => 'Test', 'required' => false), + 'first_options' => array('label' => 'Test', 'required' => true), 'second_options' => array('label' => 'Test2'), )); @@ -413,14 +413,14 @@ public function testRepeatedWithCustomOptions() ./td [./label[@for="name_first"][.="[trans]Test[/trans]"]] /following-sibling::td - [./input[@type="password"][@id="name_first"][@required="required"]] + [./input[@type="password"][@id="name_first"]] ] /following-sibling::tr [ ./td [./label[@for="name_second"][.="[trans]Test2[/trans]"]] /following-sibling::td - [./input[@type="password"][@id="name_second"][@required="required"]] + [./input[@type="password"][@id="name_second"]] ] /following-sibling::tr[@style="display: none"] [./td[@colspan="2"]/input diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index cf1ea2a4f086b..031fa53a9a761 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -94,8 +94,9 @@ public function testChoiceListAndChoicesCanBeEmpty() public function testExpandedChoicesOptionsTurnIntoChildren() { $form = $this->factory->create('choice', null, array( - 'expanded' => true, - 'choices' => $this->choices, + 'expanded' => true, + 'required' => true, + 'choices' => $this->choices, )); $this->assertCount(count($this->choices), $form, 'Each choice should become a new field'); @@ -104,10 +105,10 @@ public function testExpandedChoicesOptionsTurnIntoChildren() public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice() { $form = $this->factory->create('choice', null, array( - 'multiple' => false, - 'expanded' => true, - 'required' => false, - 'choices' => $this->choices, + 'multiple' => false, + 'expanded' => true, + 'required' => false, + 'choices' => $this->choices, )); $this->assertTrue(isset($form['placeholder'])); @@ -117,10 +118,10 @@ public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice() public function testPlaceholderNotPresentIfRequired() { $form = $this->factory->create('choice', null, array( - 'multiple' => false, - 'expanded' => true, - 'required' => true, - 'choices' => $this->choices, + 'multiple' => false, + 'expanded' => true, + 'required' => true, + 'choices' => $this->choices, )); $this->assertFalse(isset($form['placeholder'])); @@ -130,10 +131,10 @@ public function testPlaceholderNotPresentIfRequired() public function testPlaceholderNotPresentIfMultiple() { $form = $this->factory->create('choice', null, array( - 'multiple' => true, - 'expanded' => true, - 'required' => false, - 'choices' => $this->choices, + 'multiple' => true, + 'expanded' => true, + 'required' => false, + 'choices' => $this->choices, )); $this->assertFalse(isset($form['placeholder'])); @@ -143,9 +144,9 @@ public function testPlaceholderNotPresentIfMultiple() public function testPlaceholderNotPresentIfEmptyChoice() { $form = $this->factory->create('choice', null, array( - 'multiple' => false, - 'expanded' => true, - 'required' => false, + 'multiple' => false, + 'expanded' => true, + 'required' => false, 'choices' => array( '' => 'Empty', 1 => 'Not empty', @@ -159,8 +160,9 @@ public function testPlaceholderNotPresentIfEmptyChoice() public function testExpandedChoicesOptionsAreFlattened() { $form = $this->factory->create('choice', null, array( - 'expanded' => true, - 'choices' => $this->groupedChoices, + 'expanded' => true, + 'required' => true, + 'choices' => $this->groupedChoices, )); $flattened = array(); @@ -971,6 +973,7 @@ public function testSetDataMultipleNonExpandedAcceptsBoolean() public function testPassRequiredToView() { $form = $this->factory->create('choice', null, array( + 'required' => true, 'choices' => $this->choices, )); $view = $form->createView(); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php index d506f5f5a6eef..0cc82811dc899 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php @@ -36,7 +36,8 @@ public function testSetData() public function testSetOptions() { $form = $this->factory->create('repeated', null, array( - 'type' => 'text', + 'required' => true, + 'type' => 'text', 'options' => array('label' => 'Global'), )); @@ -50,6 +51,7 @@ public function testSetOptionsPerChild() { $form = $this->factory->create('repeated', null, array( // the global required value cannot be overridden + 'required' => true, 'type' => 'text', 'first_options' => array('label' => 'Test', 'required' => false), 'second_options' => array('label' => 'Test2'), @@ -117,8 +119,6 @@ public function testSetOptionsPerChildAndOverwrite() $this->assertEquals('Label', $form['first']->getConfig()->getOption('label')); $this->assertEquals('Second label', $form['second']->getConfig()->getOption('label')); - $this->assertTrue($form['first']->isRequired()); - $this->assertTrue($form['second']->isRequired()); } public function testSubmitUnequal() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy