When using Date field in forms with Symfony2, they are displayed in three different select boxes. Something like :
dd/mm/YYYY
What we would like to do is display the months in text January
, February
.... instead of 1,2,3...
How to force display in full text for the months dropdown ?
EDIT : Here is the code I use in my form class :
$builder->add('dateOfBirth', 'birthday', array(
'format' => 'dd - MM - yyyy',
'widget' => 'choice',
'years' => range(date('Y'), date('Y')-70)
));
EDIT2 : Image showing F
Look at the code of the DateType class, it has a format option:
$allowedFormatOptionValues = array(
\IntlDateFormatter::FULL,
\IntlDateFormatter::LONG,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::SHORT,
);
// If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
if (!in_array($format, $allowedFormatOptionValues, true)) {
if (is_string($format)) {
$defaultOptions = $this->getDefaultOptions($options);
$format = $defaultOptions['format'];
$pattern = $options['format'];
} else {
throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
}
}
$formatter = new \IntlDateFormatter(
\Locale::getDefault(),
$format,
\IntlDateFormatter::NONE,
\DateTimeZone::UTC,
\IntlDateFormatter::GREGORIAN,
$pattern
);
UPDATE
$builder->add('dateOfBirth', 'birthday', array(
'format' => 'dd - MMMM - yyyy',
'widget' => 'choice',
'years' => range(date('Y'), date('Y')-70)
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With