How to make multiple fields like this? Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
david0058
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Wed Jan 20, 2016 10:58 pm

How to make multiple fields like this?

Post by david0058 » Tue Feb 07, 2023 11:13 am

I can't remember what these are called? Accordion fields? Repeatable fields?

When you can click on an "add another field" and a new table row opens up?
Screenshot 2023-02-07 at 11.04.03.png
Anyway, I've used raw javascript to do this in a few components but I'd like to port the code over to using the native Joomla/Bootstrap methods, just like you get in the com_fields component. I've read through the code but the core mechanism is hidden in the complexity because that component needs to be very flexible, so I can't see the wood for the trees.

Any hints or tips? It there a simpler example that I can investigate than com_fields?

David
You do not have the required permissions to view the files attached to this post.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25057
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: How to make multiple fields like this?

Post by pe7er » Tue Feb 07, 2023 11:43 am

The Form Field Type used to be called Repeatable Fields but is now deprecated
https://docs.joomla.org/Repeatable_form_field_type

It has been replaced with the Form Field Type "Subform"
https://docs.joomla.org/Subform_form_field_type

I use it a lot because it gives you much flexibility.
On a personal website I list my Joomla + Linux presentations.

Back-end - Custom Field "Subform"
I've created a Subform "Event" that uses 3 Custom Fields:
Screenshot from 2023-02-07 12-54-46.png

Back-end - Article Edit
Which makes it possible to add multiple Events (with Fields: Name, Date and Place):
Screenshot from 2023-02-07 12-50-06.png

Front-end
At the front-end at the bottom of the article, I display those fields
together with the fields Name, Date and Place.
Screenshot from 2023-02-07 12-49-28.png
You do not have the required permissions to view the files attached to this post.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

david0058
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Wed Jan 20, 2016 10:58 pm

Re: How to make multiple fields like this?

Post by david0058 » Tue Feb 07, 2023 2:16 pm

Fantastic, thanks Peter. This is just what I need.

Migrating my custom code to subforms was a two-minute job in each case - I'd virtually re-invented the wheel :)

David

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25057
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: How to make multiple fields like this?

Post by pe7er » Tue Feb 07, 2023 3:00 pm

You're welcome!
Good to hear that you got it to work.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com


Locked

Return to “Joomla! 3.x Coding”