Welcome Guest, Not a member yet? Register   Sign In
Re-population with set_select() and arrays as field names
#1

[eluser]Bas Vermeulen[/eluser]
Hello, I'm kinda stuck with getting re-population working when I use arrays as field names for my dropdows. I'm working on a tool to update my menu's, the tool displays the menu items in a table with a row for each menu item. The table has some columns to set the attributes for the menu items, like name, type, url, etc. I want to be able to update all menu items with one save button so I use arrays as field names:

Menu item 1: name[], type[], url[]
Menu item 2: name[], type[], url[]

For the name and url fields I use normal text inputs. That didn't work out of the box with the current form validation library, but the following update from CI Reactor fixed that https://bitbucket.org/ellislab/codeignit...fc3732e593

Now I'm struggling to get that working for the dropdowns aswell.

I use the following code in my view:

Code:
<select name="type[]">
    &lt;?php foreach($types as $row): ?&gt;
        &lt;?php if($row['value'] == $menu['type']): ?&gt;
            <option name="type[]" id="type[]" value="&lt;?=$row['value']?&gt;" &lt;?php echo set_select('type[]', $row['value'], TRUE); ?&gt;>&lt;?=lang($row['name'])?&gt;</option>
        &lt;?php else: ?&gt;
            <option name="type[]" id="type[]" value="&lt;?=$row['value']?&gt;" &lt;?php echo set_select('type[]', $row['value']); ?&gt;>&lt;?=lang($row['name'])?&gt;</option>
        &lt;?php endif; ?&gt;
    &lt;?php endforeach; ?&gt;
</select>

And I use the following rule for the form validation:
Code:
$this->form_validation->set_rules('type[]', 'lang:type', 'alpha_numeric_special|required');

The table loads fine with the correct defaults being selected. But when I change the type for one menu item, and make sure to get an error from the validation library, the re-population forces the selected type to all menu items instead of just the one I updated. Does anyone have a clue what is going on here? Is my implementation wrong or is it buggy like set_value was.

Thanks in advance for your help.
#2

[eluser]Bas Vermeulen[/eluser]
Nobody experienced this problem?
#3

[eluser]Bas Vermeulen[/eluser]
It was due to a bug which I finally managed to fix: https://bitbucket.org/ellislab/codeignit...population




Theme © iAndrew 2016 - Forum software by © MyBB