/** * Adds a validation condition based on another control a returns new branch. * @param IFormControl form control * @param mixed condition type * @param mixed optional condition arguments * @return NRules new branch */ public function addConditionOn(IFormControl $control, $operation, $value = NULL) { return $this->rules->addConditionOn($control, $operation, $value); }
private function getToggleScript(NRules $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()->id); foreach ($rules as $rule) { if ($rule->type === NRule::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); } $s .= $res; } } } } return $s; }