How add empty option in Select tag for Select2 Jquery Plugin


Using php 5.6 and Phalcon 2.0 + Plugin Jquery Select2 Version: 3.5.2 From plugin documentation:

The placeholder can be declared via a data-placeholder attribute attached to the select, or via the placeholder configuration element


When placeholder is used for a non-multi-value select box, it requires that you include an empty <option></option> tag as your first option.

In my code I use Forms and Select tag: ```php $accounts = new Select( 'accountid', $options['accounts'], array( 'using' => array('id','name'), 'useEmpty' => false ) ); $accounts->setLabel('Account'); $this->add($accounts); ```

Help: How add empty option, like this: <option></option> before other options ?

edited Apr '15

Have you tried setting the following:

$accounts = new Select( 'accountid', $options['accounts'], array( 'using' => array('id','name'), "useEmpty" => true,"emptyText" => "" ) ); $accounts->setLabel('Account'); $this->add($accounts);

Notice the "useEmpty" => true,"emptyText" => ""

Also, if that doesn't work, you could try adding "emptyValue" => "" to the array

I haven't used select2 with phalcon yet, but that should, at the very least get you in the right direction to get the empty option element

Steven, Thank you.

I tried your variant before writing Post to Phalcon forum.

In case:

"useEmpty" => true,"emptyText" => "" and "emptyValue" => ""

Phalcon Select tag generate - <option value=""></option>

But, plugin needs - only <option></option> without additional attribute.