Add a new item bases on select previous
- iwory
- Member | 147
Hello,
in my form, I have a five dynamic buttons (I don't know names of than because
are from the database).
After click on one of them, I need to generate data for next radio list control. Data are selected based on button name.
Cause:
- In form, I have 5 buttons
- I click on one of them
- Form will submit by ajax
- Form return the same form plus new control which I can select
- I select one radio
- Finish form
I tried to 3 ways, but always I have a problem to get a selected button name in create form.
Have you tried somebody it?
I will glad for a small help how to resolve it.
Thank you
// createComponent
...
foreach ($seasons as $season) {
$months->addSubmit($season->getToken(), $season->getName())
->setValidationScope(false);
}
$clickedButtonValue = ???; // token
if($clickedButtonValue) {
$months = $this->seasonModel->getMonthsBySeason($clickedButtonValue);
$form->addRadioList('months', 'Month', $months);
}
...
- duke
- Member | 650
You need to anchor it manually. E.g.:
protected function createComponentFooForm()
{
$form = new UI\Form;
// TODO: add inputs (submit buttons), etc.
$this->addComponent($form, 'fooForm'); // anchors the component to the component tree under name 'fooForm'
if (!$form->isSubmitted()) {
// TODO
}
return $form;
}
If you don't anchor it yourself, it will be automatically anchored after the createComponentFooForm method returns.
- David Matějka
- Moderator | 6445
Hi, it is a bit problematic. When you submit the final form, same fields (and options for the “months” radio) has to be defined like it was defined before submitting. But you cannot recreate “months” because you won't be able to detect previously clicked submit button.
Maybe you should reconsider the design – maybe include some redirect or use radio/select instead of multiple submit buttons.