No Code Attached Yet bug
avatar laoneo
laoneo
2 Mar 2026

What happened?

In a onContentPrepareForm event, it is not possible to modify the form of a subform field for existing values. I have a simplified code like:

public function onContentPrepareForm(Form $form, $data): bool
{
	$field = $form->getField('directories', 'params');
	if ($field instanceof SubformField) {
		$field->loadSubForm()->load('<fields name="form"><fieldset name="basic"><field name="test_field" type="text" label="test label"/></fieldset></fields>');
	}

	return true;
}

If you put this code into a content plugin and open the local adapter plugin in the back end, then the text field is not displayed for the existing images and files entries. If you click on the "+" icon, then you will see that the last column in the table gets a text input field.

Version

6.0

Expected result

Modifying a subform from a field, should also reflect the changes for existing values.

Actual result

It does not.

System Information

No response

Additional Comments

@Fedik can shed maybe some light into it

avatar laoneo laoneo - open - 2 Mar 2026
avatar joomla-cms-bot joomla-cms-bot - change - 2 Mar 2026
Labels Added: No Code Attached Yet bug
avatar joomla-cms-bot joomla-cms-bot - labeled - 2 Mar 2026
avatar Fedik
Fedik - comment - 2 Mar 2026

It were not planed to work :)
That would be feature request.

However there a few issue already opened:

As workaround you basically have to modify the form for each row, additionally to what you already tried.

avatar laoneo
laoneo - comment - 2 Mar 2026

Problem is that while modifying the form in the onContentPrepareForm event, no values are set. So I can't modify the different forms there. Looks for me like a bug then, when I modify the subform at that point and it doesn't get propagated when the value instances are created.

avatar Fedik
Fedik - comment - 2 Mar 2026

In that case you can try set/modify "formsource" attribute for the subform field.

avatar laoneo
laoneo - comment - 9 Mar 2026

The whole thing is very buggy as I had to bind the data to the form in onContentPrepareForm to get all subfields for the values. In onExtensionBeforeSave i had to set the data from input, bypassing the whole validation. Not sure if this should be that broken.

avatar Fedik
Fedik - comment - 9 Mar 2026

Modify the formsource of the subform field in onContentPrepareForm, it is only reliable way to achieve what you want.
There still a few caveats, but in general should work much better than loadSubForm() or use of Form::getInstance();

In the future we need to look how to improve that.
And I think for nested subforms will not be possible to support such modifications.

Add a Comment

Login with GitHub to post a comment