form icon indicating copy to clipboard operation
form copied to clipboard

Allow Field::{button|resetButton|submitButton} in ButtonGroup::buttons()

Open Mister-42 opened this issue 6 months ago • 1 comments

It currently seems to be impossible to use both ButtonGroup and button|resetButton|submitButton at the same time. Yiisoft\Form\Field\ButtonGroup::buttons(): Argument #1 must be of type Yiisoft\Html\Tag\Button, Yiisoft\Form\Field\ResetButton given

This is problematic when attempting to use both themed ButtonGroup and Buttons at the same time.

'fieldConfigs' => [
    ButtonGroup::class => [
        'containerClass()' => ['btn-toolbar justify-content-end'],
        'inputContainerClass()' => ['btn-group'],
    ],
    ResetButton::class => [
        'buttonClass()' => ['btn btn-secondary shadow'],
        'content()' => [_('Reset')],
        'inputContainerTag()' => [null],
        'useContainer()' => [false],
    ],
    SubmitButton::class => [
        'buttonClass()' => ['btn btn-primary shadow'],
        'content()' => [_('Submit')],
        'inputContainerTag()' => [null],
        'useContainer()' => [false],
    ],
],

I propose this should be valid usage:

use Yiisoft\FormModel\Field;

echo Field::ButtonGroup()
	->buttons(
		Field::button(),
		Field::resetButton(),
		Field::submitButton()
	);

Mister-42 avatar Jul 31 '25 11:07 Mister-42