SHOW:
|
|
- or go back to the newest paste.
| 1 | protected function createComponentForm($name) | |
| 2 | {
| |
| 3 | $this[$name] = $form = new Nette\Application\UI\Form; | |
| 4 | ||
| 5 | $pairs = array('a', 'b', 'c'); // třeba z databáze
| |
| 6 | $form->addSelect('one', 'One', $pairs);
| |
| 7 | ||
| 8 | $pairsTwo = $this->model->findBy($form['one']->value); // vytahne zavisle | |
| 9 | // $pairsTwo = array('d', 'e', 'f');
| |
| 10 | $form->addSelect('two', 'Two', $pairsTwo);
| |
| 11 | } | |
| 12 | ||
| 13 | ||
| 14 | ||
| 15 | #### editace | |
| 16 | ||
| 17 | ||
| 18 | public function actionEdit($id = 0) | |
| 19 | {
| |
| 20 | $this->entity = $this->model->get($id); | |
| 21 | if (!$this->entity) {
| |
| 22 | throw new Nette\Application\BadRequestException; | |
| 23 | } | |
| 24 | } | |
| 25 | ||
| 26 | protected function createComponentEditForm($name) | |
| 27 | {
| |
| 28 | if (!$this->entity) {
| |
| 29 | throw new Nette\Application\BadRequestException; | |
| 30 | } | |
| 31 | ||
| 32 | $this[$name] = $form = new Nette\Application\UI\Form; | |
| 33 | ||
| 34 | $pairs = array('a', 'b', 'c'); // třeba z databáze
| |
| 35 | $form->addSelect('one', 'One', $pairs)
| |
| 36 | ->setDefaultValue($this->entity->one); | |
| 37 | ||
| 38 | $pairsTwo = $this->model->findBy($form['one']->value); // vytahne zavisle | |
| 39 | // $pairsTwo = array('d', 'e', 'f');
| |
| 40 | $form->addSelect('two', 'Two', $pairsTwo)
| |
| 41 | ->setDefaultValue($this->entity->two); | |
| 42 | } |