0

How can I add "data" attribute to the field type="list" in my mod_mymodule.xml like the (data="test") in the bottom example?

<field name="mylistvalue" type="list" default="" label="Select an option" description="">
  <option data="test" value="0">Option 1</option>
  <option value="1">Option 2</option>
</field>
ranslobo
  • 57
  • 7
  • Can you give a little more context please? How are you producing the form (built in, extension, Custom HTML etc) – tim.baker Dec 21 '13 at 11:48
  • The form is produced by the Joomla Framework automatically... – ranslobo Dec 21 '13 at 11:51
  • Are you thinking about what jquery does? http://demos.jquerymobile.com/1.2.0-rc.2/docs/forms/docs-forms.html or are you thinking about the generic "use this if there is nothing else" data- attribute in html5? Basically the way JFormField works it produces mark up that you have almost no control over so as AndrewEddie said you're better off cloning a field type and then you can make up your own attribute with a meaningful name. If you want to use the attribute in code if you put it in the xml it will be there in the JForm object as part of the SimpleXMLElement for the field. – Elin Dec 23 '13 at 01:21

1 Answers1

5

My assumption is you want the data attribute added to the option attribute when it's rendered on the page.

The short answer is this is not supported.

The long answer is you would have create your own field type and ship it with the extensions. This is done in many core extensions (try Banners in the administrator, for example, and look in the com_banners/models/fields folder.

What I'd probably do is take a complete copy of the JFormFieldList class and rename is to something like JFormFieldMydatalist in a file called mydatalist.php. You are then going to have to experiment with the getOptions method to add the new attribute and also change the getInput method.

In the absence of more detail about your extensions, that's the best I can do.

Andrew Eddie
  • 988
  • 6
  • 15