Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form::defaultAction() doesn’t work if actions contains CompositeFields #9975

Closed
kinglozzer opened this issue Jun 9, 2021 · 1 comment
Closed

Comments

@kinglozzer
Copy link
Member

Affected Version

4.0 - 4.8

Description

If the form “actions” FieldList contains a CompositeField as the first child, Form::defaultActions() will cause an error if the user submits the form without clicking an action button.

return $this->actions->first();

This will return the CompositeField, which then causes an error on submission when this code is reached, as actionName() doesn’t exist in CompositeField:

$funcName = $defaultAction->actionName();

Steps to Reproduce

Wrap your form action(s) in a CompositeField, e.g:

$actions = FieldList::create(
    CompositeField::create(
        FormAction::create('doMyForm', 'Submit')
    )->addExtraClass('some-css-classes')
);

return Form::create($this, __FUNCTION__, $fields, $actions, $validator);

Then submit the form without clicking the action button, e.g. with JS console:

document.querySelector('#Form_MyForm').submit();

You should see the following error:

Uncaught BadMethodCallException: Object->__call(): the method 'actionName' does not exist on 'SilverStripe\Forms\CompositeField'

@GuySartorelli
Copy link
Member

PR merged and tagged as 4.13.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants