Kdyby Replicator Dynamic v Dynamicu nezreplikuje vnoreny dynamic
- Chipso
- Člen | 28
Ahojte,
mam problem, potreboval by som zreplikovat taketo nieco:
<?php
$form->addDynamic('inputsContainer', function (Container $container) use ($translator, $addCallback) {
$months = [];
for ($m = 1; $m <= 12; $m++) {
$months[] = date('F', mktime(0, 0, 0, $m, 1, date('Y')));
}
$start = (new DateTime())->modify('-4 years');
$end = (new DateTime())->modify('+4 years');
$years = Date::getYearsBetweenInterval($start, $end);
$container->addMultiSelect('months', $translator->translate('forms.kpi.createForm.months'), $months)
->getControlPrototype()->addClass('js-example-basic-multiple');
$container->addSelect('years', $translator->translate('forms.kpi.createForm.years'), $years);
$container->addDynamic('inputs', function (Container $inputs) use ($translator) {
$inputs->addText('targetName', $translator->translate('forms.kpi.createForm.labels.name'));
$inputs->addText('interval', $translator->translate('forms.kpi.createForm.labels.interval'))
->setRequired(FALSE)
->addRule(Form::NUMERIC);
$inputs->addText('color', $translator->translate('forms.kpi.createForm.labels.color'))
->getControlPrototype()
->addClass('colorpicker')
->setAttribute('autocomplete', 'off');
}, 6);
$container->addSubmit('remove', 'Remove period')
->setValidationScope(FALSE)
->addRemoveOnClick();
}, 1)->addSubmit('add', 'Add period')
->setValidationScope(FALSE)->addCreateOnClick();
?>
Problem je ale v tom, ze pokial zavolam Add Period
zreplikuje
sa mi iba container inputsContainer
– vobec to nezareaguje na
inputs
container, ktory je vnoreny… viete mi niekto pomoct, ako
nato ?
Nette 2.4
Replicator@dev
PS: Prva forma sa mi vykresli OK, so 6 prvkami
Editoval Chipso (2. 5. 2017 20:12)
- David Matějka
- Moderator | 6445
ahoj, presny reseni ti z hlavy nereknu, ale problem je v tom, ze ten defaultni pocet kontejneru (tech 6) se vytvori jen u noveho formulare. kdyz se klikne na tlacitko, tak kdyby/replicator bere ten formular jako odeslany a neaplikuje tedy defaults.
mozna by mohlo stacit pridat onClick na tu AddPeriod a rucne ty vnitrni inputs vytvorit.
- Chipso
- Člen | 28
David Matějka napsal(a):
ahoj, presny reseni ti z hlavy nereknu, ale problem je v tom, ze ten defaultni pocet kontejneru (tech 6) se vytvori jen u noveho formulare. kdyz se klikne na tlacitko, tak kdyby/replicator bere ten formular jako odeslany a neaplikuje tedy defaults.
mozna by mohlo stacit pridat onClick na tu AddPeriod a rucne ty vnitrni inputs vytvorit.
Velmi pekne dakujem, ale neviem sa dostat zo SubmitButtonu (porpipade, ako ho rucne znovu vytvorit)
<?php
public function addElement(SubmitButton $button) {
$button->getParent()->createOne();
$button->getParent()->addDynamic('inputs', function (Container $inputs) {
$inputs->addText('targetName', $this->translator->translate('forms.kpi.createForm.labels.name'));
$inputs->addText('interval', $this->translator->translate('forms.kpi.createForm.labels.interval'))
->setRequired(FALSE)
->addRule(Form::NUMERIC);
$inputs->addText('color', $this->translator->translate('forms.kpi.createForm.labels.color'))
->getControlPrototype()
->addClass('colorpicker')
->setAttribute('autocomplete', 'off');
}, 6);
}
?>
@DavidMatějka
ku temu vnorenemu containeru., ked to vytvorim takto, nepozna to ako keby ten
container http://pasteboard.co/9qsKJVmh.png
Editoval Chipso (2. 5. 2017 20:24)
- Chipso
- Člen | 28
Prisiel som nato:
je potrebne nastavit parameter:
<?php
public function __construct($factory, $createDefault = 1, $forceDefault = TRUE)
?>
createDefaults && $forceDefaults = TRUE
cize riesenie:
<?php
$form->addDynamic('name', function(Container $name){}, $defaultContainers, TRUE);
?>
https://github.com/…ontainer.php#L514
Editoval Chipso (2. 5. 2017 20:53)