Domas
Domas

Reputation: 1133

Generating time dropdowns with empty values in CakePHP

Inside a form in one of the view files, I generate a dropdown for specifying time like following:

echo $this->Form->input('start_time', array('label'=>false, 'timeFormat' => '24', 'interval'=> '10', 'selected' => '00:00','type'=>'time')); 

it generates two dropdowns: one for hours and one for minutes. The preselected value is as stated 00:00. If no value is chosen, the dropdown shows current time.

What I want it to do instead, is to produce empty values, so the dropdown for hours would be like: " , 00, 01, 02..."

Upvotes: 1

Views: 270

Answers (1)

joshua.paling
joshua.paling

Reputation: 13952

You can just pass through 'empty' => '' as an extra param. And then, pass '' as the default value. Don't pass 'selected' at all.

Your code will look like this:

echo $this->Form->input('start_time', array('label'=>false, 'timeFormat' => '24', 'interval'=> '10', 'default' => '','type'=>'time', 'empty' => ''));

See http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs

Upvotes: 2

Related Questions