• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Repeat group check box 'make all data same'

Mono

Member
I'm not sure the title explains this well, but how do you place a check box (or other control) to make the data entered in one field in a repeat group be repeated on all?

Thank you :)
 
I wrote this code, a check box located in the repeat group, when checked copies all values of the elements in this repeat group (except any that contain 'id' in the name) into all remaining repeat groups.
It can be used on any repeat group.
Unchecking clears all data in remaining groups.

In the javascript onchange event of the checkbox I put this code
JavaScript:
populateRemainingFields(this,40);

Where 40 is the number of the repeat group.

This code is placed in form_X.js

JavaScript:
function populateRemainingFields(el,groupId) {
// get the element value ...
var x = el.getValue();


// if checkbox is checked
if (x==1){
  insertValue("no",el,groupId)
  // if the checkbox is unclicked lets remove all the data
}else{
  // if the check box is checked append new data to remaining  fields
  insertValue("delete",el,groupId);
  }
}

function insertValue(remove,el,groupId){
      // get the repeat group on which checkbox was clicked
      var myForm = 'form_1'
      var targetRepeatCount = getRepeatCount(groupId);
      var block = Fabrik.getBlock(myForm);
      // find how many repeat groups are open
      var numRepeats = block.repeatGroupMarkers[groupId];


      jQuery.each(el.form.formElements, function(key, element) {
        //Is this the same group as clicked checkbox
        if (element.groupid == groupId) {
          // do not include id items, add 'id' to element name to exclude it     
          if (key.indexOf('id')== -1) {


              //from key trim off the number of the repeat group and add #
              var targetField = ('#' + key.slice(0, -1));

              //get the value to be copied
              // if the checkbox is checked onclick use the value in the group, if not clear the field
              if (remove == "delete"){
              var targetValue = "" // jQuery(targetField + targetRepeatCount).val();
              }else{
              var targetValue = jQuery(targetField + targetRepeatCount).val();
              }
              //add 1 to group count
              var newTargetRepeatCount = targetRepeatCount + 1 

                  do {
                   //update the rest of the groups with the value
                   //console.log(targetField+newTargetRepeatCount,"=",targetValue);
                  jQuery(targetField + newTargetRepeatCount).val(targetValue);
                  newTargetRepeatCount = newTargetRepeatCount + 1;
                  }
                  while (newTargetRepeatCount < numRepeats);
            
        
          }
   
        }

      });
  }

  function getRepeatCount(groupId){

    // get the DOM object for this group ...
    var thisGroup = jQuery('#group' + groupId);
    // get a jQuery array of all the subgroups in this group ...
    var allSubGroups = jQuery(thisGroup).find('.fabrikSubGroup');
    // get the sub group the button was clicked on ...
    var targetSubGroup = event.target.getParent('.fabrikSubGroup');
    // find the index of the target subgroup in all groups
    var RepeatCount = jQuery.inArray(targetSubGroup, allSubGroups);
    return RepeatCount;
  }

Thanks to Hugh most of the work is his, I just glued it together.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top