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

Phalcon\Forms\Element\Select custom label

I have a simple table with (lets say three collumns)

id         (primary key int)

name       (varchar)

deleted    (tinyint)

and what i'm trying to do it build a select like this

    $Select = new Select('t', MyTable::find(), array(
        'using' => array('id', 'name'),
        'name' => 't[]',
        'multiple' => 'multiple'
    ));

the only thing i would like to add is...

if the field deleted is 1, concat ' - deleted' with the column name in the select...

Any ideia how to perform it?

Thank you



12.1k

In my opinion the best thing to do i a foreach on your MyTable::find() to set the name



85.5k

when i need "custom" select stuff, i just build the options for the select myself

$this->view->setVar("categories");

//volt

{% for cat in this.view.getVar("categories") %]

<option value ="{{cat.getId()"> {{ cat.getName() }}</option>

{%endfor}


5.3k
Accepted
answer

well a 'simple' workaround i found was using afterFetch on the model... and change the name propertie or add a new propertie for specific cases...

public function afterFetch() {
    if($this->deleted){
        $this->name .= ' - deleted';
    }

    //or

    if($this->deleted){
        $this->nameForSelect =  $this->name . '  - deleted';
    }else{
        $this->nameForSelect = $this->name;
    }
}