With the newly released version of Zend Framework 2, two new form elements were added; DateSelect
and MonthSelect
. I want to use the former, which adds three selects; day, month and year. However, I have a problem formatting the output how I want - and, there is no documentation for this!
I am adding the form element to my form like this (taken from this page):
$this->add(array(
'type' => 'Zend\Form\Element\DateSelect',
'name' => 'birthDate',
'options' => array(
'label' => 'Date',
'create_empty_option' => true,
'day_attributes' => array(
'data-placeholder' => 'Day',
'style' => 'width: 20%',
),
'month_attributes' => array(
'data-placeholder' => 'Month',
'style' => 'width: 20%',
),
'year_attributes' => array(
'data-placeholder' => 'Year',
'style' => 'width: 20%',
)
)
));
For outputting, I am doing like this:
echo $this->formDateSelect($form->get('birthDate'));
The thing is that I don't know how to control the way the selects are formatted. For instance, they are currently outputted in this form: [month] [day], [year]
. I want to change two things; first, I want to switch the day and month, and secondly, I want to get rid of the comma.
The helpers use the IntlDateFormatter
class to format the selects. In the source code, I noticed that you can use the predefined constants for the date type when calling __invoke()
[link to source code], like this:
echo $this->formDateSelect($form->get('birthDate'), IntlDateFormatter::SHORT);
Having tried all of the constants, I still cannot get the format I want.
I noticed that there are getters for the three selects, but using the formSelect
view helper with each of them, empty selects are rendered because the data population is within the new view helpers. So that pretty much defeats the purpose of even using the selects individually; then I might as well just use regular selects.
Does anyone have any idea how I can gain more control on how my selects are formatted? Is it even possible without too much hassle, or should I just use three regular selects for maximum flexibility?
echo $this->formDateSelect($this->form->get('birthDate'), IntlDateFormatter::LONG, 'ro_RO');
. Thank you very much for your answer - it is very appreciated! – Cigarette