How to Add Custom Attributes for Joomla Form Fields

Joomla is indeed a great CMS with great features and flexibility. Sometimes it does not have native API support for some specific functions that we need badly but due to the flexibility of Joomla, allow us to implement what we want without hazard.

I was working on this medical lab project a couple of months ago. End users needed to navigate through form fields via tab button while omitting certain fields. So it’s pretty simple right ? all I need to bind tab press with some sort of javascript and set tab index for the fields accordingly. But there was a problem. When we use Joomla API to develop components we use XML to setup forms. This form XML file then rendered as a usual form of Joomla API. Joomla AIP has all most all attributes for this XML form fields. But unfortunately, Joomla form fields attribute definition does not support “tab index ” attribute.

Fortunately, Joomla provides us the ability to override anything of it’s API. So I just overrode the form fields definition by simply copying text.php (I needed to setup tab index to text fields only) from Site Root \ libraries\joomla\form\fields to My component\models\fields directory.Then I can simply add field definition to XML file like this.

here is the overrode field definition.

That’s it, folks. That’s how you create a custom attribute for Joomla standard form field.

Leave a Reply