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

1

119

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')
)
Crime answered 20/2, 2017 at 1:12 Comment(10)
Seems like SelectionGroup doesn't have a SelectionGroup_small.ss template which is used when you nest fields. Just create it in your theme and modify it. Could also be worth raising an issue on githubVirile
@Virile not having much luck with that. Anything else I can do to make it work?Crime
adding ->setSmallFieldHolderTemplate('SelectionGroup_small') to the SelectionGroup starts to fix it however using the markup from SelectionGroup doesn't fix the issue (thought it would look odd but be somewhat functional, it brings back the radio boxes but none of the fields beneath work).Crime
I've also added a git issue github.com/silverstripe/silverstripe-framework/issues/6637Crime
Already old item but perhaps still curious: What is the result as source-code? In general it's possible that the fields are all in the source, but just hidden for some formatting reasons.Hebrides
Sorry @Hebrides I'm a bit lost with your question.Crime
@Crime I just meant what was the produced HTML?Hebrides
@Hebrides Oh, I can't remember but it wasn't in the generated HTML, think it was a div for the button but no content inside it that I would have expected.Crime
This is not a great question, and I don't know how it garnered 57 upvotes, especially given the low view count, but I guess it's not going anywhere because of that. Your problem is with the generated HTML, but you don't provide it, or provide an example of the desired HTML output. Your code sample is syntactically invalid, and no context is provided as to where it is used. If you solved this somehow, you should post an answer; if the problem is no longer relevant or reproducible, you should delete the question.Commutate
@Commutate it's to do specifically with the SilverStripe framework (hence the tag) and a bug has been posted on the GitHub repository (linked in the comments). The reason there is no html is because there is no html template for the given functions, that is the bug. Besides a semi colon at the end I've got no idea what you're talking about it being syntactically invalid. Anyone who is familiar with the framework will know the context for it. It is still an open bug and easily reproducible.Crime
A
1

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.

Arand answered 12/11, 2019 at 1:4 Comment(1)
@Crime did this code work to get around SilverStripe framework's bug?Arand

© 2022 - 2024 — McMap. All rights reserved.