Using CakePHP, I created select-option form element with:
echo $form->select('items', $numeration , array('selected' => 0));
It creates selection box, but the first option is always empty.
How can I get rid of that empty option? I did not manage to do anything with showEmpty
option...
please help.... :-((
UPDATED:
cakephp code
echo $form->select('myOptions', array(1 => 'a', 2 => 'b', 3 => 'c'), array('empty'=>false));
creates next html:
<select id="myOptions" name="data[myOptions]">
<option selected="selected" value=""></option>
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
</select>
what is wrong, and why do i have empty element?!
It's better to use:
$this->Form->input('items', array('options'=>$numeration));
By default it's without empty element. but to force it fully use
$this->Form->input('items', array('empty'=>false, 'options'=>$numeration));
According to the docs the third argument is the default item to be selected. If you don't want an empty option to appear change your code to:
echo $form->select('items', $numeration , NULL, array('empty' => false));
This works under 2.3:
$options = array('0'=>'Zero','1'=>'One');
echo $this->Form->select('field-name',$options,array('empty'=>false));
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