contributte / forms-multiplier

:repeat: Form multiplier & replicator for Nette Framework
https://contributte.org/packages/contributte/forms-multiplier.html
MIT License
26 stars 21 forks source link

Access to SubmitButtons #80

Closed ne0-cz closed 1 year ago

ne0-cz commented 1 year ago

Hi, I can't seem to be able to access neither CreateButton's or RemoveButton's SubmitButton. All my submit buttons are actually <button>s instead of <input>s which is easily done for Form submit by extending Nette\Application\UI\Form:

public function addSubmit($name, $caption = NULL): SubmitButton
    {  
        $button = parent::addSubmit($name, $caption);

        $element = $button->getControlPrototype();
        $element->setName('button');
        $element->setType('submit');
        $element->setText($caption);

        return $button;
    }

I'd love to do the same for the multiplier buttons. It is actually useful to use real <button>s in some cases - I add icons to my icons via CSS this way (<input>s don't do CSS ::before/::after pseudo-elements). Thanks!

MartkCz commented 1 year ago

Hi, did you try https://github.com/contributte/forms-multiplier/blob/master/src/Buttons/CreateButton.php#L35-L40 and https://github.com/contributte/forms-multiplier/blob/master/src/Buttons/RemoveButton.php#L28-L33 in https://github.com/contributte/forms-multiplier/blob/master/src/Multiplier.php#L169-L177 ?

ne0-cz commented 1 year ago

@MartkCz Aha, that's it, thanks!

For future reference:

$multiplier->addRemoveButton('Remove')
    ->addOnCreateCallback(function($button) {
        $button->getControlPrototype()
            ->setName('button')
            ->setType('submit')
            ->setText($button->getCaption());
    });