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
 public function enable()
 {
     $this->validateScript = '';
     $this->toggleScript = '';
     $this->central = TRUE;
     foreach ($this->form->getControls() as $control) {
         $script = $this->getValidateScript($control->getRules());
         if ($script) {
             $id = $control->htmlId;
             $setId = $control->getControlPrototype()->id;
             if ($setId) {
                 $id = $setId;
             }
             if (!$control instanceof RadioList) {
                 $this->validateScript .= "if(this.passed['{$id}'] && (sender.id=='{$id}'";
             } else {
                 $this->validateScript .= "if(this.passed['{$id}'] && (sender=='{$id}'";
             }
             foreach ($control->rules as $rule) {
                 if ($rule->type === Rule::CONDITION) {
                     // this is condition
                     $this->validateScript .= " || sender.id=='" . $rule->control->htmlId . "' ";
                 }
             }
             $this->validateScript .= ")) {\n\t\t";
             if (!$control instanceof RadioList) {
                 $this->validateScript .= "\n\t\tvar validated_element = document.getElementById('{$id}');\n\t";
             } else {
                 $this->validateScript .= "\n\t\tvar validated_element = document.getElementById('{$id}-0').parentNode.lastElementChild;\n\t";
             }
             $this->validateScript .= "\n\t\t{$script} \n\t";
             $this->validateScript .= "} \n\t";
         }
         $this->toggleScript .= $this->getToggleScript($control->getRules());
         if ($control instanceof ISubmitterControl && $control->getValidationScope() !== TRUE) {
             $this->central = FALSE;
         }
     }
     if ($this->validateScript || $this->toggleScript) {
         foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\IFormControl') as $control) {
             $control->getControlPrototype()->onchange("{$this->validateControlFunction}(this);", TRUE);
             $control->getControlPrototype()->onblur("{$this->validateControlFunction}(this);", TRUE);
             /*if($control instanceof RadioList) {
                   $control->getControlPrototype()->onchange("$this->validateControlFunction('{$control->getHtmlId()}');", TRUE);
                   $control->getControlPrototype()->onblur("$this->validateControlFunction('{$control->getHtmlId()}');", TRUE);
               }*/
             if ($this->validateOnKeyUp && $control instanceof TextBase) {
                 $control->getControlPrototype()->onkeyup("{$this->validateControlFunction}(this, event);", TRUE);
             }
         }
         foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\ISubmitterControl') as $control) {
             if ($control->getValidationScope()) {
                 $control->getControlPrototype()->onclick("return {$this->validateFunction}(this)", TRUE);
             }
         }
     }
 }
 /**
  * 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";
 }
 static function dumpErrors(Form $form)
 {
     if (!$form->hasErrors()) {
         return '';
     }
     $s = '<ul>';
     foreach ($form->getErrors() as $id => $error) {
         $s .= '<li>' . $id . ': ' . $error . '</li>';
     }
     foreach ($form->getControls() as $control) {
         $s .= self::dumpControlError($control);
     }
     $s .= '</ul>';
     return $s;
 }
 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 #8
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 #9
0
 /**
  * @covers Form::getControls
  */
 public function testAddControls()
 {
     $this->myForm->setValue('verify', 'required');
     $this->myForm->addControl('verify', new \Textbox('phone'));
     $this->assertArrayHasKey('verify', $this->myForm->getControls());
 }