Skip to content

How to use the multiplier for editing #104

@tomminok

Description

@tomminok

Hello
I'm trying to use a multiplier in a data editing form.
According to the records in the database, the appropriate number of Multiplier elements must be displayed.

Unfortunately, I don't know how to properly access the multiplier components.

Can you state the correct use of the multiplier for editing?

$defHeader = json_decode($defVals->header, true);
            
$multiplier = $form->addMultiplier('multiplier', function (\Nette\Forms\Container $container, \Nette\Forms\Form $form) {
    $arrHlavicka = $this->webhookModel->getHlavicka(['stav'=>1])->fetchPairs("nazev", "nazev");

    $container->addSelect('hlavicka', 'Hlavička',$arrHlavicka)
        ->setHtmlAttribute('class', 'form-control')
        ->setHtmlAttribute("placeholder", 'Vyberte hlavičku')
        ->setPrompt('Vyberte hlavičku');

    $container->addText('hlavickaval', 'Request Header')
        ->setHtmlAttribute('class', 'form-control')
        ->setHtmlAttribute("placeholder", 'Hodnota hlavičky');    
}, count($defHeader));   

$multiplier->addCreateButton('Přidat hlavičku')
      ->addClass('btn btn-success');

foreach($defHeader as $k => $v){
    $hlavicka[] = [ 'hlavicka' => $k, 'hlavickaval' => $v ];
}

foreach ($multiplier as $index => $container) {
    $hlavicka = $container->getComponent('hlavicka');
    $hlavickaval = $container->getComponent('hlavickaval');
    
    // Nastavení výchozích hodnot
    $hlavicka->setDefaultValue($hlavicka[$index]['hlavicka']);
    $hlavickaval->setDefaultValue($hlavicka[$index]['hlavickaval']);

    // Přidání tlačítka RemoveButton
    $container->addRemoveButton('Smazat')
              ->addClass('btn btn-danger');
}

Thank you
Thomas

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions