SilverStripe PHP Forms - If I nest a SelectionGroup inside a FieldGroup, one of the related SelectionGroup_Items' Radio Box does not show up. Why?

PhpFormsSilverstripe

Php Problem Overview


I have a form that has two FieldGroups, and in one of the FieldGroups I have a SelectionGroup.

The SelectionGroup_Items show up in the form FieldGroup but the radio boxes to select one of the options doesn't show. If I remove the FieldGroup it then works again.

I've looked at the framework templates, and if I change the FieldGroup_holder.ss SmallFieldHolder to FieldHolder the radio boxes appear again and work correctly. I've tried following the templates to see which one isn't obeying the SelectionGroup but I keep getting lost.

Here's an example bit of code

$fields = FieldList::create(
	FieldGroup::create(
		TextField::create('Name', 'Name')
	),
	FieldGroup::create(
		SelectionGroup::create(
			'Test1or2',
			array(
				SelectionGroup_Item::create(
					'Test1', array(
						TextField::create('Test1', 'Test1')
					),
					'Test1'
				),
				SelectionGroup_Item::create(
					'Test2', array(
						TextField::create('Test2', 'Test2')
					),
					'Test2'
				)
			)
		)
	)
),
FieldList::create(
	FormAction::create('submit', 'Submit')
)

Php Solutions


Solution 1 - Php

You could add another fieldset then set it's attributes to id="hidden_field" aria-hidden="true". In the css document you could do the following.

    #hidden_field{
        display:none;
        height:0;
        width:0;
        margin:0;
        padding:0;
        visibility: hidden;
    }

This should hide SilverStripe Framework's query behavior. In my own php forms I had random brackets appearing whenever someone submitted a new form numerous times under different part-id numbers. I used this approach to hide the random brackets on my site.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRudigerView Question on Stackoverflow
Solution 1 - PhpJTSView Answer on Stackoverflow