Skip to content

Commit 32af7d0

Browse files
committed
[Form] BirthdayType has automatic attr when widget is single_text
1 parent d7d9be3 commit 32af7d0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* Add `LazyChoiceLoader` and `choice_lazy` option in `ChoiceType` for loading and rendering choices on demand
1010
* Use `form.post_set_data` instead of `form.pre_set_data` in `ResizeFormListener`
1111
* Change the priority of `DataCollectorListener` from 255 to -255
12+
* `BirthdayType` will now have default `attr` values when in `widget` option is set to `single_text`
1213

1314
7.1
1415
---

src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@ class BirthdayType extends AbstractType
1818
{
1919
public function configureOptions(OptionsResolver $resolver): void
2020
{
21+
$options = $resolver->resolve();
2122
$resolver->setDefaults([
22-
'years' => range((int) date('Y') - 120, date('Y')),
2323
'invalid_message' => 'Please enter a valid birthdate.',
2424
]);
25+
if ($options['widget'] === 'single_text') {
26+
$resolver->setDefaults([
27+
'attr' => ['min' => date('Y-m-d', strtotime('120 years ago')), 'max' => date('Y-m-d')],
28+
]);
29+
} else {
30+
$resolver->setDefaults([
31+
'years' => range((int) date('Y') - 120, date('Y')),
32+
]);
33+
}
2534

2635
$resolver->setAllowedTypes('years', 'array');
2736
}

0 commit comments

Comments
 (0)