laminas / laminas-form

Validate and display simple and complex forms, casting forms to business objects and vice versa
https://docs.laminas.dev/laminas-form/
BSD 3-Clause "New" or "Revised" License
80 stars 52 forks source link

FormRow: allow attributes for <fieldset> wrapper #62

Open Slamdunk opened 4 years ago

Slamdunk commented 4 years ago
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.

froschdesign commented 4 years ago

@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!

Slamdunk commented 4 years ago

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:

froschdesign commented 4 years ago

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