Welcome Guest, Not a member yet? Register   Sign In
Why does the form_helper() accept an array of attributes?
#1

[eluser]redguy[/eluser]
I noticed that the form_dropdown() function doesn't accept an Array of attributes. I've been trying to add an id attribute to the <select>, but the only way I've been able to do that is by:
Code:
&lt;?=form_dropdown('number_of_answers', $no_answers, $default_no_answers, 'id="number_of_answers" class="select"')?&gt;
Trying to pass an Array doesn't work (obvious if you see check the form_dropdown() code).

So I'm wondering why you can't pass an array of attributes as in form_input(), form_textarea(), form_radio(), etc.

I came to this prolem (well, atleast for me), because my <select> needs an id attribute for my jQuery to work. I don't seem to break anything if I change line 260 of the form_helper() from:
Code:
$form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
to:
Code:
$form = '<select name="'.$name.'" id="'.$name.'"'.$extra.$multiple.">\n";

What is the design decision behind this behaviour? Since it's different than the other form_helper() functions.
#2

[eluser]richthegeek[/eluser]
redguy - if you are feeling confident you can rewrite the form helpers - I know I have rewritten quite a bit of CI. The cardinal rule is "make it work the same as default, use flags to make it alter it's behaviour"
#3

[eluser]garymardell[/eluser]
You could do it the old fashioned way and just write the html Tongue
#4

[eluser]Jay Turley[/eluser]
I had to add id=$name functionality to the form helper for the hidden input fields to make them work with jQuery. I now see from this post that I will need to add it to the drop-down list function as well.

Like you, redguy, I wonder why this choice was made. It was a pain in the butt to track down in the first place ;-)
#5

[eluser]redguy[/eluser]
The changed code (w/o a flag) seems to work. At least I'm not getting any errors :-p. And it should work, because all I did was add a piece of String to another String. And that String isn't used to do some operations on. So as long as no other part of CI depends on a specific form_dropdown() format I should be fine.




Theme © iAndrew 2016 - Forum software by © MyBB