public function createComponentCartForm($name) { // Nevolat v konstruktoru, protoze, pokud se jedna o handling akce (?do=cartControl-default), tak je konstruktor // zavolan jeste pred sablonou a nema tudiz nastavene potrebne vazby (resilo by to attached()?) IntegerPicker::register(); $form = new Form($this, $name); $form->onSuccess[] = callback($this, 'cartFormSubmitted'); foreach ($this->order->getItems(true) as $item) { $form->addCheckbox('check' . $item->uniqueId); $form->addIntegerPicker('range' . $item->uniqueId)->setDefaultValue($item->amount)->addRule(function ($control) { return $control->value >= 0; }, 'Zadané číslo musí byt nula či vyšší')->addRule(Form::FILLED, 'Vyplňte prosím počet produktů'); } $form->addSubmit('delete', 'Delete selected'); $form->addSubmit('reCount', 'Recount'); $form->addSubmit('buy', 'Buy'); return $form; }
public function createComponentAdjustOrderForm($name) { vBuilder\Application\UI\Form\IntegerPicker::register(); $form = new Form($this, $name); $form->addHidden('ids'); if ($form->isSubmitted()) { $this->setProductIds(explode(',', $form->values->ids)); } else { $form['ids']->setDefaultValue(implode(',', $this->getProductIds())); } foreach ($this->products as $product) { $form->addIntegerPicker('amount' . $product->pageId)->setDefaultValue(1)->addRule(function ($control) { return ctype_digit($control->value); }, 'The amount must be a number!'); } $form->onSuccess[] = callback($this, $name . 'Submitted'); $form->onError[] = callback($this, $name . 'Error'); $form->addProtection(); $form->addSubmit('s', 'Přidat do košíku'); return $form; }