public function enable() { $el = $this->form->getElementPrototype(); if (!$el->name) { $el->name = 'frm-' . ($this->form instanceof AppForm ? $this->form->lookupPath('Nette\\Application\\Presenter', TRUE) : $this->form->getName()); } $this->validateScripts = array(); $this->toggleScript = ''; $this->central = TRUE; foreach ($this->form->getControls() as $control) { $script = $this->getValidateScript($control->getRules()); if ($script) { $this->validateScripts[$control->getHtmlName()] = $script; } $this->toggleScript .= $this->getToggleScript($control->getRules()); if ($control instanceof ISubmitterControl && $control->getValidationScope() !== TRUE) { $this->central = FALSE; } } if ($this->validateScripts || $this->toggleScript) { if ($this->central) { $this->form->getElementPrototype()->onsubmit("return nette.validateForm(this)", TRUE); } else { foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\ISubmitterControl') as $control) { if ($control->getValidationScope()) { $control->getControlPrototype()->onclick("return nette.validateForm(this)", TRUE); } } } } }