Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jak správně předat setDefaults z Action #54

Open
jAKErCZ opened this issue Sep 15, 2020 · 2 comments
Open

Jak správně předat setDefaults z Action #54

jAKErCZ opened this issue Sep 15, 2020 · 2 comments
Labels

Comments

@jAKErCZ
Copy link

jAKErCZ commented Sep 15, 2020

Čau,
mám dotaz snažím se přijít na to jak správně z Action metody nastavit multiplieru defaultní hodnoty tak jako se klasicky dělá.

viz...

 $this['eventTermForm']->setDefaults([
                    'terms_id' => $terms->terms_id,
                    'event_id' => $terms->event_id,
                    //'date' => $terms->date,
                    'price' => $terms->price,
                    'capacity' => $terms->capacity
                ]);

A formulář

protected function createComponentEventTermForm() {
        $copies = 1;
        $maxCopies = 7;
        $form = new Form();
        $form->addHidden('terms_id');
        $form->addSelect('event_id', '', $this->termsRepository->getSelectEvent())
            ->setPrompt('Vyberte Lekci')
            ->setRequired('Lekce je povinná!');
        $multiplier = $form->addMultiplier('multiplier', function (\Nette\Forms\Container $container, \Nette\Forms\Form $form) {
            $container->addText('date')
                ->setRequired('Datum je povinné!');
        }, $copies, $maxCopies);
        $multiplier->addCreateButton('Přidat další datum')
            ->addClass('btn btn-primary');
        $multiplier->addRemoveButton('Odstranit datum')
            ->addClass('btn btn-danger');
        $form->addText('price')
            ->setRequired('Cena je povinná!');
        $form->addText('capacity')
            ->setRequired('Kapacita je povinná!');
        $form->addCheckbox('all');
        $form->addSubmit('send');
        $form->onSuccess[] = [$this, 'eventTermFormSucceeded'];

        return $form;
    }

Hledal jsem nějaké řešení ale nic moc jsem nenašel díky moc...

@MartkCz
Copy link
Member

MartkCz commented Oct 21, 2020

V masteru by mělo fungovat:

$this['eventTermForm']->setDefaults([
			'multiplier' => [
				['date' => '2042'],
				['date' => '2043'],
				['date' => '2044'],
			],
		]);

@jAKErCZ
Copy link
Author

jAKErCZ commented Nov 29, 2020

V masteru by mělo fungovat:

$this['eventTermForm']->setDefaults([
			'multiplier' => [
				['date' => '2042'],
				['date' => '2043'],
				['date' => '2044'],
			],
		]);

Super tak to funguje 👍
Oprava:

 $formDate = new DateTime($terms->date);
                $this['eventTermForm']->setDefaults([
                    'terms_id' => $terms->terms_id,
                    'event_id' => $terms->event_id,
                    'multiplier' => [
                        ['date' => $formDate->format('Y-m-d\TH:i:s')]
                    ],
                    'price' => $terms->price,
                    'capacity' => $terms->capacity
                ]);

Poté se to tam zobrazuje v pořádku :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants