Dynamicky formular
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- odin
- Člen | 50
Pokousim se udelat takovy formular, kde kdyz vyberu polozku z jednoho
selectu, tak se podle toho aktualizuje obsah druheho selectu. Zatim mam
nasledujici kod, ale to pada na tom, ze onFilterClicked() se spusti az po
createComponentFilterForm(), cili do selectu se nactou hodnoty, ktere
neodpovidaji te zvolene ve formulari.
<?php
protected function createComponentFilterForm($name) {
$form = new AppForm($this, $name);
$form->addSelect('cbGrammar', 'Grammar:', GrammarModel::getGrammarPairsByPack('arithmetic'))
->setDefaultValue($this->listSettings->grammarId);
$form->addSelect('cbService', 'Service:', ServicesModel::getServicePairsByGrammar($this->listSettings->grammarId))
->setDefaultValue($this->listSettings->serviceId);
$form->addSelect('cbPopulation', 'Population:', $this->model->getPopulationPairsByService($this->listSettings->serviceId))
->setDefaultValue($this->listSettings->populationId);
$form->addSelect('cbGeneration', 'Generation:', $this->model->getGenerationPairsByPopulation($this->listSettings->populationId))
->setDefaultValue($this->listSettings->generation);
$form->addSubmit('bFilter', 'Filter')->onClick[] = array($this, 'onFilterClicked');
return $form;
}
?>
<?php
public function onFilterClicked(SubmitButton $button) {
$this->listSettings->grammarId = $this['filterForm']['cbGrammar']->value;
$this->listSettings->serviceId = $this['filterForm']['cbService']->value;
$this->listSettings->populationId = $this['filterForm']['cbPopulation']->value;
$this->listSettings->generation = $this['filterForm']['cbGeneration']->value;
}
?>
V zasade je to cele filtr, kde kdyz v prvnim selectu neco vyberu tak se to
zobrazi v datagridu, a soucasne se nacte obsah dalsiho selectu. Pokud to dal
upresnim v dalsim selectu, zase se aktualizuje datagrid a nabidne se dalsi
select s upresnenim, atd…
Ma to nejake rozumne reseni?