
Note: From Joomla 3.6 Subform form field is introduced and repeatbale form field will be removed from Joomla 4.0. So if you are developing for j3.6 or upper then use subform form field.
Joomla 3.2 added a nice feature introducing repeatable standard form field. Now it’s easy to add repeat fields just defined from the standard xml file of any joomla extensions. For each repeat box you can add multiple fields (joomla standard form fields ), means you can add fields under fields !
Now we will go more technical but will try our best to write it for new joomla developer.
Step1:
Write a new field in xml like any other standard field. Here the only new thing is field type “Repeatable” and icon
Step2:
Now add hidden fieldset inside the field and the field set name should be your field name _modal , means here the hidden fieldset name we need to add myrepeatfield_modal and it confirms the modal window (in which you will actually get the repeatable fields interface) will have the html id attribute myrepeatfield_modal_table.
If you are trying to add repeat field in a module then please save the module edit window and see the field you add in step one should have a list icon and click it, it will open a modal and you will see a first blank text field, there will be */- buttons to add more or delete. Try yourself and save, now save the module edit window again, now click the field list icon again to open the popup and see you have those fields !
Step3:
The way we added a hidden field set and inside it we added a field named customfield1 we can add more standard joomla form fields.
Step4:
If you finished up to step 3 then I think you already confident to use this in your next extension if applicable. In this last step we will try to show some default values for fields. The repeat fields are saved as json object and if you write the default values as json object then it will work. For our 3rd step we added two fields inside the hidden field set, means in repeat box we will get two fields where one is text and another one is textarea.
Now we will see how we can put default values for two repeat box.
Now the question may come how can I get the value from the field or while I try to get the field value from Joomla params get method i.e, Example $params->get(‘myrepeatfield’) I get some json like value. Yes, you are right, just do json_decode() ;)
Hope you enjoyed the joomla native repeatable fields without using any custom library or 3rd party resource. Please note that, this features is available from jomola 3.2 and it’s recommended that you follow the latest version. Joomla now maintain one major version.
Share Joomla love if you care !
Leo Wg
How do I can to use this subform field type for add more fields to the com_content?
Sabuj Kundu
Hi, for this you need to write a system plugin and add method like this https://gist.github.com/manchumahara/3573b0bce59b2fd4e417a0c80ca9ae78 where in the param folder you need to put your custom xml file named “com_content.article.xml” as per my sample code . the xml file sample code https://gist.github.com/manchumahara/f0ca985b10860b5246202f892be1e55f
now if you override the joomla com_content article or any view, you can get extra fields in attribs fields
here is sample code how you can get attribs values outside of com_content or in other component or plugin
https://gist.github.com/manchumahara/3b371216d8b1e73ca38160e22ce93f63
Selim Rana
Hi, it’s not work with media field, have you any solution for it?
Sabuj Kundu
Didn’t check this yet, I think in next joomla releases will bring fix. btw, repeatable field will no longer be supported as there is more innovative new one sub form field which has the repeatable feature https://docs.joomla.org/Subform_form_field_type