phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.79k stars 1.96k forks source link

[BUG]: Phalcon\Html\Helper\Input\Select not working correctly #16625

Open FaimMedia opened 4 months ago

FaimMedia commented 4 months ago

Describe the bug Following this example: https://docs.phalcon.io/5.7/volt/#tag-helpers It shows you should place inputSelect in a loop chained to an add function to add options. Not surprisingly, this just spits out x number of select fields, with only one option (see screenshots). So obviously the documentation is wrong here, but reviewing the source, I cannot find a method for adding a list of options directly? (Phalcon 3.4 had a using option: https://docs.phalcon.io/3.4/volt/#using-tag-helpers). How to do this in Phalcon 5.7?

To Reproduce Steps to reproduce the behavior:


$this->view->typeOptions = [
    4 => 'Type 4',
    8 => 'Type 8',
];
<div class="row row-label">
    <label>Type:</label>

    {% for id, name in typeOptions %}
        {{ inputSelect('type').addPlaceholder('Select type').add(name, id) }}
    {% endfor %}
</div>

Expected behavior One select field with provided multiple options.

// paste code

Screenshots If applicable, add screenshots to help explain your problem.

Scherm­afbeelding 2024-07-13 om 15 03 19 Scherm­afbeelding 2024-07-13 om 15 03 09

Details

niden commented 4 months ago

I might have to rewrite this component. There are a couple of features that are a bit difficult to use to get the result you need.

This code should do what you need to do:

$this->view->typeOptions = [
    4 => 'Type 4',
    8 => 'Type 8',
];
<div class="row row-label">
    <label>Type:</label>
    {% assign select = inputSelect('    ', PHP_EOL, ['name' : 'type', 'placeHolder' : 'Select type']) %}

    {% for id, name in typeOptions %}
        {{ select.add(name, id) }}
    {% endfor %}
    {{ select }}
</div>

I am thinking, in alignment with what you mention, to have more methods for this. For instance we can have a method setAttributes to change whatever we like before the element is rendered and also have something like setOptions that will accept the array (the same thing as using)

I will work on this most likely this weekend.