1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Add new repeat group with javascript

Discussion in 'Community' started by Mono, Mar 15, 2019.

  1. Mono

    Mono Member

    Level: Community
    Hope someone can help me here. I am trying to open a form that has a repeat group, using js, that displays records already entered but also with a new empty set of elements. I thought that inserting a value into 1 of the elements in the next repeat group may work, but it doesn't seem to.
    The rowid 17 has 1 record so I made a url to open that record and add a new record at the same time.
    Here is my URL for the form but it doesn't create a new set of repeat groups.

    Code (Javascript):
    tbl_faults_43_repeat___severity is a dropdown

    Any ideas?
    Last edited: Mar 18, 2019
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    You'd have to do it with some JS, in ./components/com_fabrik/js/form_X.js (where X is your numeric form ID).

    Something like ..

    Code (Text):

    requirejs(['fab/fabrik'], function() {
       Fabrik.addEvent('fabrik.form.loaded', function(form) {
          // replace 123 with your numeric group ID
    -- hugh
  3. Mono

    Mono Member

    Level: Community
    As always a great help, I don't know what I'd do without you.

    Here is what I came up with in the form_X.js of my popup.
    I'd perhaps of preferred to do it in the requesting forms JS but this worked for me.

    Code (Javascript):
    Fabrik.addEvent('fabrik.form.elements.added', function () {

    function addRepeatIfNeeded() {

             //Find how many repeat groups are open
              var noOfRepeats = $('group43').getElements('.fabrikSubGroup').length;
              var lastRepeat = noOfRepeats - 1;
            // If the last one is empty then don't make a new one. The field in question is a required field.

                 if( jQuery('#tbl_faults_43_repeat___fault_description_' + lastRepeat).val() ) {                        
                               requirejs(['fab/fabrik'], function() {
                               var form = Fabrik.getBlock('form_18');

    I can't even conceive how to achieve my next problem.

    Can I make the new repeat group appear above the already populated repeat groups and set the focus in a field?

Share This Page