laminas-form icon indicating copy to clipboard operation
laminas-form copied to clipboard

FormRow: allow attributes for <fieldset> wrapper

Open Slamdunk opened this issue 4 years ago • 3 comments

Q A
New Feature yes
RFC no
BC Break no

Hi, so far the <fieldset> wrapper for multi-checkbox, radio and so on can't have attributes since the rendered html is hard-coded:

https://github.com/laminas/laminas-form/blob/c3ad4db5a26a8c99a812463c2eea6244887bf18a/src/View/Helper/FormRow.php#L193-L202

For the multi-checkbox, an hypothetical $multiCheckbox->setAttribute('fieldset_class' => 'foo'); could be retrieved and injected: we should think of a comprehensive solution for all the involved elements though.

Slamdunk avatar Apr 01 '20 06:04 Slamdunk

@Slamdunk Thanks for this request!

For the multi-checkbox, an hypothetical $multiCheckbox->setAttribute('fieldset_class' => 'foo'); could be retrieved and injected: we should think of a comprehensive solution for all the involved elements though.

The question which arise here: is the FormRow helper the correct place to handle the fieldset?

The helper FormCollection already contains a "wrapper" functionality. Maybe we can adopt this functionality to all helper with multiple elements and also for the FormRow helper itself. This would allow to create custom wrappers for the different element types and to create a markup with the FormRow helper which is used by CSS frameworks like Bootstrap, Tailwind and Co.

Please attach further ideas and thoughts!

froschdesign avatar Apr 01 '20 07:04 froschdesign

The helper FormCollection already contains a "wrapper" functionality. Maybe we can adopt this functionality to all helper with multiple elements and also for the FormRow helper itself.

That's indeed a good suggestion :+1:

[...] to create a markup with the FormRow helper which is used by CSS frameworks like Bootstrap, Tailwind and Co

In fact that's what I was looking for: avoid custom styling and rely solely to external CSS tools. This should be the path for any view helper these days: classes allowed everywhere :ship:

Slamdunk avatar Apr 01 '20 08:04 Slamdunk

I think the goal for standard forms should be:

<?= $this->form($form) ?>

which means we need support for configurations like this:

return [
    'view_helper_config' => [
        'form_row' => [
            'input_error_class' => 'is-invalid',
            'wrapper'           => '…',
            'label_wrapper'     => '…',
        ],
    ],
];

or (pseudo code)

return [
    'view_helper_config' => Laminas\Form\View\Helper\HelperConfig::BOOTSTRAP,
];
return [
    'view_helper_config' => Laminas\Form\View\Helper\HelperConfig::FOUNDATION,
];

Compare also with Laminas\View\Helper\Service\FlashMessengerFactory:

https://github.com/laminas/laminas-view/blob/b74443fd42490caf2b92959f8867fb232f8ac52f/src/Helper/Service/FlashMessengerFactory.php#L38-L50

froschdesign avatar Apr 23 '20 06:04 froschdesign