I need to add attributes to my tag, like class, id or custom ones
the current Form API does not allow that, so I did a small change to form_select_options function
this is my first pach, so forgive me if I screw something :)
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | 414562.patch | 679 bytes | attiks |
| #22 | 414562.patch | 684 bytes | attiks |
| #20 | 414562-add-attributes-for-options.patch | 697 bytes | attiks |
| #19 | 414562-add-attributes-for-options.patch | 697 bytes | attiks |
| #17 | 414562-add-attributes-for-options.patch | 701 bytes | attiks |
Comments
Comment #1
afeijoAfter rich debate with michaelfavia and Berdir, here is a new patch with the code more drupal style, using #options and element_children()
thanks guys
Comment #2
berdir- Another minor point, always use curly braces, even for single line statements.
- I think you need to pass only the "real" childrens through, call it like: form_select_options($element, element_children($choice));
Comment #3
afeijochanges done :)
Comment #4
afeijoComment #5
afeijoto use it its simple
instead of:
'#options' => array('text 1', 'text 2');
use like this:
'#options' => array(
array('#value' => 'text 1', '#attributes' => array('class' => 'c1', )),
array('#value' => 'text 1', '#attributes' => array('class' => 'c2', )),
);
Comment #6
michaelfavia commentedWhile i think this is an improvement over the first patch (still need to be roled against the project and not against the file alone), I would prefer to see "options" promoted to first class elements in FAPI instead (like checkbox is).
We could combine alot of the shared logic for form processing and display. The only impediment mentioned by Berdir and the only ones i foresee are that options cant be used alone (we could automatically provide a select with just one option in this case if wed like) and that options have OPTGTOUPS for structured arrays. But i think we could handle this fairly easily.
Comment #7
afeijoI found a conflict with that change and the FAPI protection
here is the new patch
Comment #8
afeijonow with the right path so the bot wont scream
Comment #10
sunsubscribing
Comment #11
chx commenteddont mess with #options, use an #options_attributes instead.
Comment #12
afeijoThat was my initial approach
I will do the appropriate changes and post a new patch today
thanks guru
Comment #13
afeijoHere it is, much simpler, just 3 lines change
Comment #14
afeijoit had a debug char, removed.
Comment #15
afeijofixed cvs head
(I'm such a cvs noob, sorry)
Comment #17
attiks commentednew patch against head
Comment #19
attiks commentedtry again
Comment #20
attiks commentedgrrr
Comment #22
attiks commentedfinal try ;p
Comment #24
attiks commentedagain :/
Comment #26
casey commentedCrosslinking:
#284917: Allow FAPI select, radios, and checkboxes to specify some options as disabled
#342316: Introduce proper Form API #types for 'option' and 'optgroup', and make #options consistent.
Comment #27
casey commentedComment #28
sunProper architectural discussion and work happens in #342316: Introduce proper Form API #types for 'option' and 'optgroup', and make #options consistent.