Here I have added data-attri" /> Here I have added data-attri" /> Here I have added data-attri"/>

Joomla 3.x - How to add & access data attribute in jForm

222 Views Asked by At

For example,

<field name="name" type="text" required="ture" data-attribute-type="Guest" data-attribute-subtype="Guest1"/>

Here I have added data-attribute-type="Guest" and data-attribute-subtype="Guest1" these attributes and assigned values to it. Now I want to access those attributes/values while rendering jForm

<input type="text" name="jform[name]" id="jform_name" required="required" data-attribute-type="Guest" data-attribute-subtype="Guest1" >

1

There are 1 best solutions below

0
user101289 On

You need to access custom attributes via the elements array like this:

Form field (I don't think you want to use data attributes):

<field name="myfieldname" type="myfieldname" required="true" access-type="Guest" access-subtype="Guest1"/>

Then you need to define a custom Field and do your magic (probably in render or renderField:

class JFormFieldMyFieldName extends JFormField
{
    public function renderField($options = array())
    {
        $access_type = $this->element['access_type']);
        $access_subtype = $this->element['access_subtype']);

        // do whatever
    }
}

This is all untested but hopefully gets you moving in the right direction.