nette / forms

đź“ť Generating, validating and processing secure forms in PHP. Handy API, fully customizable, server & client side validation and mature design.
https://doc.nette.org/forms
Other
498 stars 147 forks source link

Add common interface to ControlGroup and Container #131

Open richard-ejem opened 8 years ago

richard-ejem commented 8 years ago

Common interface declaring getControls() would be useful for form renderers including DefaultFormRenderer.

Example:

interface IControlContainer
{
    /** @return IControl[] */
    public function getControls();
}

then, DefaultFormRenderer::renderControls() could look like:

public function renderControls(Nette\Forms\IControlContainer $parent) {
    # got rid of this check:
    # if (!($parent instanceof Nette\Forms\Container || $parent instanceof Nette\Forms\ControlGroup)) {
    #     throw new Nette\InvalidArgumentException('Argument must be Nette\Forms\Container or Nette\Forms\ControlGroup instance.');
    # }
}

If agreed, I can pullrequest it

jtojnar commented 8 years ago

Why not make ControlGroup implement IContainer? It would also allow to have groups inside groups and get rid of the weird setCurrentGroup() switching.

Isn’t the left one just more natural?

richard-ejem commented 8 years ago

Yes it is, but it is a major API change, maybe for Nette 3 one day :) for now, unifying them using interface would be more likely a simple fix of current state.

f3l1x commented 7 years ago

Maybe it could simplify the whole thing that ControlGroup and Container should merge it together.

ControlGroup is just for form.fieldset? I mean graphic purpose?

dg commented 7 years ago

ControlGroup is any general group of controls. I think that it is used only for graphic purposes.

f3l1x commented 7 years ago

What about drop it at all? We could use container for that too?

dg commented 7 years ago

It is not easy.

``` php $form = new UI\Form; $g1 = $form->addGroup('Group 1'); $g1->addText('foo', 'Foo'); $g2 = $form->addGroup('Group 2'); $g2->addText('bar', 'Bar'); ``` ``` php $form = new UI\Form; $g1 = $form->addGroup('Group 1'); $form->setCurrentGroup($g1); $form->addText('foo', 'Foo'); $g2 = $form->addGroup('Group 2'); $form->setCurrentGroup($g2); $form->addText('bar', 'Bar'); ```