/** * Nastavi vychozi tridy vsem elementum * @param Form $form */ public function setupDefaultClasses($form) { if ($form->getElementPrototype()->class) { $form->getElementPrototype()->class = [$form->getElementPrototype()->class]; } $form->getElementPrototype()->class[] = 'form-horizontal'; $this->classButtons($form); foreach ($form->getControls() as $control) { if ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox || $control instanceof \Vodacek\Forms\Controls\DateInput || $control instanceof Controls\UploadControl) { if ($control instanceof Controls\UploadControl) { continue; } if ($control->getControlPrototype()->class) { $control->getControlPrototype()->class = [$control->getControlPrototype()->class]; } if (!$control->getOption('no-form-control')) { $control->getControlPrototype()->class[] = 'form-control'; } if ($control->isRequired()) { $control->getControlPrototype()->class[] = 'required'; } } elseif ($control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) { $control->getSeparatorPrototype()->setName('div')->class($control->getControlPrototype()->type); } elseif ($control instanceof Controls\Checkbox) { $control->getLabelPrototype()->class[] = 'checkbox'; } } }
public function enable() { $this->validateScript = ''; $this->toggleScript = ''; $this->central = TRUE; foreach ($this->form->getControls() as $control) { $script = $this->getValidateScript($control->getRules()); if ($script) { $this->validateScript .= "do {\n\t{$script}} while(0);\n\n\t"; } $this->toggleScript .= $this->getToggleScript($control->getRules()); if ($control instanceof ISubmitterControl && $control->getValidationScope() !== TRUE) { $this->central = FALSE; } } if ($this->validateScript || $this->toggleScript) { if ($this->central) { $this->form->getElementPrototype()->onsubmit("return {$this->validateFunction}(this)", TRUE); } else { foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\ISubmitterControl') as $control) { if ($control->getValidationScope()) { $control->getControlPrototype()->onclick("return {$this->validateFunction}(this)", TRUE); } } } } }
private function getToggleScript(Rules $rules, $cond = NULL) { $s = ''; foreach ($rules->getToggles() as $id => $visible) { $s .= "visible = true; {$cond}\n" . "nette.toggle(" . json_encode((string) $id) . ", " . ($visible ? '' : '!') . "visible);\n"; } $formName = json_encode((string) $this->form->getElementPrototype()->name); foreach ($rules as $rule) { if ($rule->type === Rule::CONDITION && is_string($rule->operation)) { $script = $this->getClientScript($rule->control, $rule->operation, $rule->arg); if ($script) { $res = $this->getToggleScript($rule->subRules, $cond . "{$script} visible = visible && " . ($rule->isNegative ? '!' : '') . "res;\n"); if ($res) { $el = $rule->control->getControlPrototype(); if ($el->getName() === 'select') { $el->onchange("nette.forms[{$formName}].toggle(this)", TRUE); } else { $el->onclick("nette.forms[{$formName}].toggle(this)", TRUE); //$el->onkeyup("nette.forms[$formName].toggle(this)", TRUE); } $s .= $res; } } } } return $s; }
/** * Renders form end. * @return string */ public static function renderFormEnd(Form $form) { $s = ''; if (strcasecmp($form->getMethod(), 'get') === 0) { $url = explode('?', $form->getElementPrototype()->action, 2); if (isset($url[1])) { foreach (preg_split('#[;&]#', $url[1]) as $param) { $parts = explode('=', $param, 2); $name = urldecode($parts[0]); if (!isset($form[$name])) { $s .= Html::el('input', array('type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1]))); } } } } foreach ($form->getComponents(TRUE, 'HiddenField') as $control) { if (!$control->getOption('rendered')) { $s .= $control->getControl(); } } if (iterator_count($form->getComponents(TRUE, 'TextInput')) < 2) { $s .= '<!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->'; } echo ($s ? "<div>{$s}</div>\n" : '') . $form->getElementPrototype()->endTag() . "\n"; }
/** * Renders form end. * @return string */ public function renderEnd() { $s = ''; foreach ($this->form->getControls() as $control) { if ($control instanceof HiddenField && !$control->getOption('rendered')) { $s .= (string) $control->getControl(); } } if ($s) { $s = $this->getWrapper('hidden container')->setHtml($s) . "\n"; } return $s . $this->form->getElementPrototype()->endTag() . "\n"; }
public function enable() { $this->validateScript = ''; $this->toggleScript = ''; $this->central = TRUE; foreach ($this->form->getControls() as $control) { $this->validateScript .= $this->getValidateScript($control->getRules()); $this->toggleScript .= $this->getToggleScript($control->getRules()); if ($control instanceof ISubmitterControl && $control->getValidationScope() !== TRUE) { $this->central = FALSE; } } if ($this->validateScript || $this->toggleScript) { if ($this->central) { $this->form->getElementPrototype()->onsubmit = "return " . $this->validateFunction . "(this)"; } else { foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\ISubmitterControl') as $control) { if ($control->getValidationScope()) { $control->getControlPrototype()->onclick .= 'return ' . $this->validateFunction . "(this);"; } } } } }
/** * Renders form end. * @return string */ public function renderEnd() { $s = ''; foreach ($this->form->getControls() as $control) { if ($control instanceof HiddenField && !$control->getOption('rendered')) { $s .= (string) $control->getControl(); } } if (iterator_count($this->form->getComponents(TRUE, 'TextInput')) < 2) { $s .= '<!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->'; } if ($s) { $s = $this->getWrapper('hidden container')->setHtml($s) . "\n"; } return $s . $this->form->getElementPrototype()->endTag() . "\n"; }
/** * Generates the client side validation script. * @return void */ public function renderClientScript() { $this->form->getElementPrototype()->attrs['data-nette-rules'] = json_encode($this->exportContainer($this->form)); }