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

selectStatic add standard option

Hi Community!

I have

{{ selectStatic(["g", genres, "using":["id", "name"], "class": "form-control"]) }}

The genres is filled by

$this->view->genres = Genres::find();

Here the genres are all filled by entries from the database. But I also want the default "Not chosen" with the value "-1". Is this possible with volt syntax? If it's not not I can add the default entry to the database. Which I want to avoid

greets

I think you want just select() and not selectStatic(). You should be able to add something like:

{{ select(["g", genres, "using":["id", "name"], "class": "form-control", 'useEmpty': true, 'emptyText': 'Not chosen', 'emptyValue': '-1']) }}


12.1k

Hey! Thanks for your answer but I get an error. Which phalcon-version are you using?

Invalid arguments supplied for memnstr()

Invalid data provided to SELECT helper

Not totally sure what the issue might be. What does the compiled volt template look like from app/cache/volt ? At some point, it might be more advisable to just create a form class and then use {{ form.render('g') }} that's in the sample app to render it out.



12.1k

Hey Mark,

sorry for answering so late:(

Here the part from the compiled volt template:

<?php echo $this->tag->select(array(array('g', $genres, 'using' => array('id', 'name'), 'class' => 'form-control', 'useEmpty' => true, 'emptyText' => 'Not chosen', 'emptyValue' => '-1'))); ?>

I'll try your advice to create a form class.

Thanks