Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



4.5k

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



75.3k

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}


3.2k
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;
    }
}