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 :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

afeijo’s picture

FileSize
1.31 KB

After rich debate with michaelfavia and Berdir, here is a new patch with the code more drupal style, using #options and element_children()

thanks guys

Berdir’s picture

Status: Needs review » Needs work

- 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));

afeijo’s picture

FileSize
1.44 KB

changes done :)

afeijo’s picture

Status: Needs work » Patch (to be ported)
afeijo’s picture

Status: Patch (to be ported) » Needs review

to 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', )),
);

michaelfavia’s picture

While 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.

afeijo’s picture

FileSize
1.83 KB

I found a conflict with that change and the FAPI protection

here is the new patch

afeijo’s picture

FileSize
1.88 KB

now with the right path so the bot wont scream

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Title: How to add custom attributes to a <select> <option> tag? » Allow to add custom attributes to a <select> <option> tag
chx’s picture

dont mess with #options, use an #options_attributes instead.

afeijo’s picture

That was my initial approach

I will do the appropriate changes and post a new patch today

thanks guru

afeijo’s picture

Status: Needs work » Needs review
FileSize
622 bytes

Here it is, much simpler, just 3 lines change

afeijo’s picture

FileSize
619 bytes

it had a debug char, removed.

afeijo’s picture

FileSize
818 bytes

fixed cvs head
(I'm such a cvs noob, sorry)

Status: Needs review » Needs work

The last submitted patch failed testing.

attiks’s picture

Status: Needs work » Needs review
FileSize
701 bytes

new patch against head

Status: Needs review » Needs work

The last submitted patch, 414562-add-attributes-for-options.patch, failed testing.

attiks’s picture

try again

attiks’s picture

Status: Needs work » Needs review
FileSize
697 bytes

grrr

Status: Needs review » Needs work

The last submitted patch, 414562-add-attributes-for-options.patch, failed testing.

attiks’s picture

Status: Needs work » Needs review
FileSize
684 bytes

final try ;p

Status: Needs review » Needs work

The last submitted patch, 414562.patch, failed testing.

attiks’s picture

Status: Needs work » Needs review
FileSize
679 bytes

again :/

Status: Needs review » Needs work

The last submitted patch, 414562.patch, failed testing.

casey’s picture

Version: 7.x-dev » 8.x-dev
sun’s picture

Status: Needs work » Closed (duplicate)