developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #718: #718-trunk-spaces-donotfire-errors.2.patch

File #718-trunk-spaces-donotfire-errors.2.patch, 6.2 KB (added by bibo, 12 years ago)

v2 with unit tests

  • lib/jelix-www/js/jforms_jquery.js

     
    22* @package      jelix
    33* @subpackage   forms
    44* @author       Laurent Jouanneau
    5 * @contributor  Julien Issler
     5* @contributor  Julien Issler, Dominique Papin
    66* @copyright    2007-2008 Laurent Jouanneau
    7 * @copyright    2008 Julien Issler
     7* @copyright    2008 Julien Issler, 2008 Dominique Papin
    88* @link         http://www.jelix.org
    99* @licence      GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
    1010*/
     
    5757            var elt = frmElt.elements[c.name];
    5858            if (!elt) continue; // sometimes, all controls are not generated...
    5959            var val = this.getValue(elt);
    60             if(val == ''){
     60            var trimVal = val;
     61            if (val.replace)
     62                var trimVal = val.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
     63            if(trimVal == ''){
    6164                if(c.required){
    6265                    this.tForm.errorDecorator.addError(c, 1);
    6366                    valid = false;
     
    657660        alert(message);
    658661    }
    659662};
    660 
  • lib/jelix-www/js/jforms_light.js

     
    22* @package      jelix
    33* @subpackage   forms
    44* @author       Laurent Jouanneau
    5 * @contributor  Julien Issler
     5* @contributor  Julien Issler, Dominique Papin
    66* @copyright    2007-2008 Laurent Jouanneau
    7 * @copyright    2008 Julien Issler
     7* @copyright    2008 Julien Issler, 2008 Dominique Papin
    88* @link         http://www.jelix.org
    99* @licence      GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
    1010*/
     
    6666            var elt = frmElt.elements[c.name];
    6767            if (!elt) continue; // sometimes, all controls are not generated...
    6868            var val = this.getValue(elt);
    69             if(val == ''){
     69            var trimVal = val;
     70            if (val.replace)
     71                var trimVal = val.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
     72            if(trimVal == ''){
    7073                if(c.required){
    7174                    this.tForm.errorDecorator.addError(c, 1);
    7275                    valid = false;
     
    666669        alert(message);
    667670    }
    668671};
    669 
  • lib/jelix/forms/jFormsControl.class.php

     
    44* @subpackage  forms
    55* @author      Laurent Jouanneau
    66* @contributor Loic Mathaud, Dominique Papin, Julien Issler
    7 * @copyright   2006-2008 Laurent Jouanneau, 2007 Dominique Papin
     7* @copyright   2006-2008 Laurent Jouanneau, 2007-2008 Dominique Papin
    88* @copyright   2007 Loic Mathaud
    99* @copyright   2008 Julien Issler
    1010* @link        http://www.jelix.org
     
    5858
    5959    function check(){
    6060        $value = $this->container->data[$this->ref];
    61         if($value == '') {
     61        if(trim($value) == '') {
    6262            if($this->required)
    6363                return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED;
    6464        }elseif(!$this->datatype->check($value)){
     
    394394    public $required = true;
    395395    function check(){
    396396        $value = $this->container->data[$this->ref];
    397         if($value == '') {
     397        if(trim($value) == '') {
    398398            return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED;
    399399        }elseif($value !=  $this->container->privateData[$this->ref]){
    400400            return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID;
     
    686686class jFormsControlRepeat extends jFormsControlGroups {
    687687    public $type="repeat";
    688688}*/
    689 
  • testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

     
    33* @package     testapp
    44* @subpackage  unittest module
    55* @author      Jouanneau Laurent
    6 * @contributor Julien Issler
     6* @contributor Julien Issler, Dominique Papin
    77* @copyright   2007-2008 Jouanneau laurent
    8 * @copyright   2008 Julien Issler
     8* @copyright   2008 Julien Issler, 2008 Dominique Papin
    99* @link        http://www.jelix.org
    1010* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
    1111*/
     
    4646        $this->assertFalse($this->form->check());
    4747        $this->form->setData('nom','');
    4848        $this->assertFalse($this->form->check());
     49        $this->form->setData('nom','    ');
     50        $this->assertFalse($this->form->check());
    4951        $ctrl->required = false;
    5052        $this->assertTrue($this->form->check());
    5153
     
    9092        $this->assertTrue($this->form->check());
    9193        $this->form->setData('nom','1');
    9294        $this->assertTrue($this->form->check());
    93        
     95
    9496        $ctrl->required = true;
    9597        $this->form->setData('nom',null);
    9698        $this->assertFalse($this->form->check());
     
    101103        $this->form->setData('nom','0');
    102104        $this->assertFalse($this->form->check());
    103105        $this->form->setData('nom','1');
    104         $this->assertTrue($this->form->check());       
     106        $this->assertTrue($this->form->check());
    105107    }
    106108
    107109    function testCheckboxes() {
     
    175177        $ctrl = new jFormsControlCaptcha('captcha');
    176178        $this->form->addCtrl($ctrl);
    177179
     180        // captcha required by default $ctrl->required = true;
     181        $this->assertFalse($this->form->check());
     182        $this->form->setData('captcha','');
     183        $this->assertFalse($this->form->check());
     184        $this->form->setData('captcha','    ');
     185        $this->assertFalse($this->form->check());
     186
    178187        $ctrl->initExpectedValue();
    179188
    180189        $this->assertTrue(isset($this->form->getContainer()->privateData['captcha']));