Removal of all initial repeat clones reappear

Cr CraigH 30 Dec, 2025

There is a problem in Chronoforms ver 8.0.51 relating to removal of all repeat clones when there were some initialsed in the form.

How to reproduce:

  1. Form has a repeater area with "start count" = 0
  2. Form has some php that populates some clones (this would normally be from a DB read)
  3. Form starts with the initial clones displayed.
  4. You remove them all and do not add any more
  5. Submit the form and look at the debug data on the next page

Env

  • CF: 8.0.51
  • Joomla: 5.4.1

Result:

The next page debug shows the initial repeat data for the clones that were deleted. Thus any PHP processing would also use this deleted data.

If you keep at least one clone then the data correctly reflects the clones submitted.

At the moment I don't know how to work around this issue and its stopped migration of my last form from CF7

Simple form to demonstrate the issue attached

Cr CraigH 03 Jan, 2026

Hopefully there will be a fix for this issue in a forthcoming CF8 release. In the interim I have implemented a workaround that works OK in my form migrations from CF7 that I will share in case it is of use for others. I have written a javascript listener function to be used in a form submit event that will check for empty repeater areas (Ie ones where the number of clones is zero).If not found the script adds a hidden input field with name "repeater_name" to the form with the value set to an empty array.

/******************************************************************************************************
/* function OnSubmitFn(arg1)
/*
/* event callback function for form submit.
/* it will look for repeater sections with no clones
/* if no clones found it will ensure there is a hidden field added with the name attribute set to the 
/* name of the empty repeater.
/* If clones are found, it will ensure the above field, if it exists is removed.
/* Note this submit event may be triggered before any validations are performed, hence the submit can subsequently
/* not take place.
/* Hence the additional processing/checking of the existence of the added field.
/*
/* If using this script, then a php action is requred on the start page to 
/* unset the $this->data['repeater_name'] data entry if no clones are being initialised.
/* 
/*****************************************************************************************************/
function OnSubmitFn(arg1) {
	event.target.form.querySelectorAll('.clonable[data-startCount="0"]:not(.clone)').forEach( (node) => {
		let repeaterSelector = node.getAttribute("data-selector");
		let repeaterName = repeaterSelector.split(".")[2];
		let emptyRepeaterInput = event.target.form.querySelector('[name="'+repeaterName+'"]');
		if( node.parentNode.querySelectorAll('.clone[data-selector="'+repeaterSelector+'"]').length >0) {
			if( emptyRepeaterInput ) {
				event.target.form.removeChild(emptyRepeaterInput);
			}
		}
		else {
			if( !emptyRepeaterInput ) {			
				var input = document.createElement('input');
				input.setAttribute("type", "hidden");
				input.name = repeaterName;
				input.value = [];
				event.target.form.appendChild(input);   
			}			
		}
		
	})
}

This allows subsequent PHP submit actions to determine whether or not there are actually any repeats in the submitted form data ie it caters for the situation where the form started off with initial repeats that were removed before form submission.

Note as the submit event occurs before form field validations are done, the actual submit POST may not occur, hence there is logic to check if the added field already exists or not.

Note On adopting this approach you have to cater for navigating back to the start page and if the number of repeats are empty a php action is needed to unset the above field that was added ie  unset($this->data['repeater_name']);  If you do not do this unsetting, then you get a PHP exception in  ~/administrator/components/com_chronoforms8/pages/chronoforms/views/area_repeater/output.php (17) 

The approach does not attempt to empty the various initialised clones' fields, in my submit actions I simply ignore them if $this->data['repeater_name'] is empty.

(I suppose another, arguably, simpler workaround would have been to simply add a hidden field that keeps count of the number of clones created for each repeater area and use this in submit action php code).

Post a Reply