degee147
degee147

Reputation: 255

Cakephp 4 Form Helper: Create Individual dropdown for day, month and year

So, in CakePHP 3, to get something like this:

date month and year dropdown

I would do this:

 <?= $this->Form->date('dob', [
   'templates' => ['inputContainer' => '{{content}}'], 'label' => false, 'class' => 'form-control', 'minYear' => 1940, 'maxYear' => date('Y') - 5,
   'empty' => [
      'year' => "Year", // The year select control has no option for empty value
      'month' => 'Month', // The month select control does, though
      'day' => 'Day', // The month select control does, though
   ],
 ]) ?>

However, if I try to do the same thing on Cakephp 4, I get this

enter image description here

I've gone through the docs here: https://book.cakephp.org/3/en/views/helpers/form.html#creating-date-time-related-controls and https://book.cakephp.org/4/en/views/helpers/form.html

Please how can I achieve same Cakephp 3 output on Cakephp 4

Upvotes: 0

Views: 696

Answers (1)

mark
mark

Reputation: 21743

Did you try

'type' => 'select'

as documented? Otherwise a custom template might help.

Alternatively, the dropdown default part was moved to Shim plugin See https://github.com/dereuromark/cakephp-shim/blob/master/docs/View/Form.md That should give you the 3.x way of creating such form elements.

Upvotes: 1

Related Questions