I am working with a Drupal 7 site; I have a vocabulary setup with an additional text field. On one of my content-type nodes, this is rendered as a drop-down select box with all the terms under that vocabulary. However, I would also like for the additional vocabulary field to be included as a data-country attribute. It is rendered rendered as follows.

<select id="..." name="..." class="...">
    <option value="145">UK8</option>

I'd like it to be rendered as follows.

<select id="..." name="..." class="...">
    <option value="145" data-country="United Kingdom">UK8</option>

Is this possible?


Unfotunately there is no way to do it using Form API. You need to involve some theming. Please check the following answer:


  • 1
    Hey Inamil, thanks for the reply and the SO link. I'll check it out and post back here. – Shalan Jul 29 '13 at 9:32

There is Form Options Attributes module wich adds support for the attributes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.