1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice
  2. If you update to Joomla 3.9.16, you will have to update Fabrik from the latest GitHub version, to fix a bug introduced in Joomla, which makes it impossible to list front end folder locations in backend JForms. This affects things like template selection.
    Dismiss Notice

FORM - Populate Repeat Group with items

Discussion in 'Professional Support' started by nbradshaw, Jun 9, 2017.

  1. nbradshaw

    nbradshaw Member

    Level: Community
    I am needing a way to populate a repeat group with a list of items from another table (items) on NEW (form).

    So for instance (example):

    items table:
    item column:
    printer
    laptop
    PC

    I would like to pre-populate the repeat group with all of the rows in the items table.

    Is there a solution for this?

    Thanks
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Not easily, no.

    Two options:

    1) Write a custom template, that rewrites default_repeatgroup.php to insert groups stocked with data, which you'd have to get by hand from the database. And stocking the data into the template is non-trivial.

    2) Write a PHP form plugin, running onLoad, which does this:

    Checks to see if there's a rowid.
    If not, manually create a row in the main table, get the insert ID for it (rowid), then manually insert the repeat group rows, setting parent_id to the insert id.
    Issue a redirect to the form, with the rowid set.

    That way rather than editing a new form, you will actually be editing an existing form, with the repeat data already present.

    Drawback there is, you've got an "uncompleted" row in your table, if they don't submit the form they loaded.

    -- hugh
     
  3. nbradshaw

    nbradshaw Member

    Level: Community
    Thanks Hugh! I will give option 2 a try.
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Iirc, on a couple of the sites I did this on, I added a hidden 'submitted' element, and a little form submission script to set that to 1 when the form is actually submitted. When I pre-create the rows, I set date_time to current time, and submitted to 0. Then I added a "garbage collection" cron job to look for rows with submitted not set to 1, and date_time > 1 hour, and delete them (and related repeat rows). That gets rid of rows where people load the form but never submit it.

    It's not entirely trivial to get this going, but it's not crazy hard. Just a bit fiddly.

    The last site I did this for was a "leisure center" with swimming pools, who need to do water quality tests every 3 hours. So when they load the main form, I check to see if there's a row dated for today, if not I pre-create it, and then add X repeat groups for the periodic testing. That site is still going strong.

    -- hugh
     

Share This Page