Add new repeat group with javascript

Mono

Member
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.

JavaScript:
index.php?Itemid=&option=com_fabrik&task=form.view&formid=18&rowid=17&tbl_faults_43_repeat___severity_1=2

tbl_faults_43_repeat___severity is a dropdown

Any ideas?
 
Last edited:
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:
requirejs(['fab/fabrik'], function() {
   Fabrik.addEvent('fabrik.form.loaded', function(form) {
      // replace 123 with your numeric group ID
      form.mockDuplicateGroup('123');
   });
});

-- hugh
 
Hugh
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.

JavaScript:
Fabrik.addEvent('fabrik.form.elements.added', function () {
  addRepeatIfNeeded();
})

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');
                           form.mockDuplicateGroup('43');
                            });
             }


}

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?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top