Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BirthdayType with widget single_text is pretty much useless #58621

Open
@garak

Description

@garak

Description

BirthdayType is just a decoration of DateType with a convenient choice of years.
Unfortunately, if you use the "single_text" widget option, it becomes useless because there is no longer a choice of years.
In this case, it would be nice if, instead of passing the "years" option to DateType, it would pass the "attr" option, with min/max instead.

Example

this code

<?php
// use...

class MyFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('foo', BirthdayType::class, ['widget' => 'single_text'],
    }
}

should behave like if I wrote

<?php
// use...

class MyFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('foo', BirthdayType::class, [
            'widget' => 'single_text',
            'attr' => ['min' => date('Y-m-d', strtotime('120 years ago)), 'max' => date('Y-m-d')]
        ],
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions