Example #1
0
 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);
                 }
             }
         }
     }
 }
 public function enable()
 {
     $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, 'ISubmitterControl') as $control) {
                 if ($control->getValidationScope()) {
                     $control->getControlPrototype()->onclick("return nette.validateForm(this)", TRUE);
                 }
             }
         }
     }
 }
Example #3
0
 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);
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * Generates the client side validation script.
  * @return string
  */
 public function renderClientScript()
 {
     $s = '';
     if ($this->validateScript) {
         $s .= "{$this->validateControlFunction} = function(sender, e) {\n\t" . "this.passed[sender.id] = true;\n\t" . "if(e && e.keyCode == 9)\n\t\t" . "return true;\n\t" . "var element, message, res;\n\t" . "var b = true;\n\t" . $this->validateScript . "return b;\n};\n" . "{$this->validateCalled} = false;\n" . "{$this->validateFunction} = function(submitter) {\n\t var b = true;\n" . "\t {$this->validateCalled} = true;\n";
         $init = "passed : { \n";
         foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\IFormControl') as $control) {
             $id = $control->htmlId;
             $setId = $control->getControlPrototype()->id;
             if ($setId) {
                 $id = $setId;
             }
             $s .= "\t b = {$this->validateControlFunction}(document.getElementById('{$id}')) && b; \n";
             $init .= "\t'{$id}':false,\n";
         }
         $init = substr($init, 0, strlen($init) - 2);
         $init .= "\n}";
         if ($this->doAlertOnSubmit) {
             $s .= "\tif(b == false) {\n\t\t" . $this->doAlertOnSubmit . ";\n\t" . "}\n";
         }
         $s .= "\treturn b; \n};\n";
     }
     if ($this->toggleScript) {
         $s .= "{$this->toggleFunction} = function(sender) {\n\t" . "var element, visible, res;\n\t" . $this->toggleScript . "\n};\n\n" . "{$this->toggleFunction}(null);\n";
     }
     if ($s) {
         $s = "var " . $this->name . " = {\n {$init} };\n" . $s;
         if ($this->compressCode) {
             $s = str_replace(array("\n", "\t"), " ", $s);
         }
         return "<script type=\"text/javascript\">\n" . "/* <![CDATA[ */\n" . $s . "/* ]]> */\n" . "</script>";
     }
 }
 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);";
                 }
             }
         }
     }
 }
Example #6
0
 /**
  * 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";
 }
Example #7
0
 /**
  * Generates the client side validation script.
  * @return string
  */
 public function renderClientScript()
 {
     $s = '';
     if ($this->validateScript) {
         $s .= "function {$this->validateControlFunction}(sender) {\n\t" . "var element, message, res;\n\t" . "var b = true;\n\t" . $this->validateScript . "return b;\n}\n" . "var {$this->validateCalled} = false;\n" . "function {$this->validateFunction}() {\n\t var b = true;\n" . "\t {$this->validateCalled} = true;\n";
         $i = 0;
         foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\IFormControl') as $control) {
             $id = $control->htmlId;
             $setId = $control->getControlPrototype()->id;
             if ($setId) {
                 $id = $setId;
             }
             $s .= "\t b = {$this->validateControlFunction}(document.getElementById('{$id}')) && b; \n";
         }
         $s .= "\treturn b; \n}\n";
     }
     if ($this->toggleScript) {
         $s .= "function {$this->toggleFunction}(sender) {\n\t" . "var element, visible, res;\n\t" . $this->toggleScript . "\n}\n\n" . "{$this->toggleFunction}(null);\n";
     }
     if ($s) {
         return "<script type=\"text/javascript\">\n" . "/* <![CDATA[ */\n" . $s . "/* ]]> */\n" . "</script>";
     }
 }
Example #8
0
 /**
  * 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";
 }