We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Disable form select entity by function

Hi,

I have a select form entity like this:

use \Phalcon\Forms\Element\Select;

$select = new Select('select', array(
    'NULL' => '',
    'a' => 'Option 1',
    'b' => 'Option 2',
));

I would like to have Option 1 to be disabled if some variable is true. How can I do that? Wanted result:

<select>
  <option value=""></option>
  <option value="" disabled>Option 1</option>
  <option value="">Option 2</option>
</select>


85.5k

I would do it the old facion way:

in my view:


foreach ($this->view->mySelectOptions AS $key => $value){

                $disabled = "";

                if ($value['myTruOption'] === true){
                    $disabled = "disabled=\"disabled\"";
                }

                echo "<option $disabled>".$value['name]'."</option>";
            }

in the controller


$this->view->setVar('mySelectOptions', MyWonderfulModel::find() /* ->toArray() ?*/ );