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 #635: 635-jForms-add-support-of-the-required-attribute-on-checkebox.2.diff

File 635-jForms-add-support-of-the-required-attribute-on-checkebox.2.diff, 7.0 KB (added by Julien, 13 years ago)

updated patch with unit tests and updated relaxNG shcemas

  • testapp/modules/jelix_tests/tests/jforms.compiler_1_1.html_cli.php

     
    33* @package     testapp
    44* @subpackage  unittest module
    55* @author      Jouanneau Laurent
    6 * @contributor Loic Mathaud, Dominique Papin
     6* @contributor Loic Mathaud, Dominique Papin, Julien Issler
    77* @copyright   2007-2008 Jouanneau laurent
    88* @copyright   2007 Loic Mathaud, 2008 Dominique Papin
     9* @copyright   2008 Julien Issler
    910* @link        http://www.jelix.org
    1011* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
    1112*/
     
    899900array('type','checkbox','myfile')
    900901),
    901902array(
    902 '<checkbox ref="nom" xmlns="http://jelix.org/ns/forms/1.1" required="true">
    903     <label>Votre nom</label>
    904 </checkbox>',
    905 'jelix~formserr.attribute.not.allowed',
    906 array('required','checkbox','myfile')
    907 ),
    908 array(
    909903'<secret ref="pwd" defaultvalue="toto"  xmlns="http://jelix.org/ns/forms/1.1">
    910904<label>Votre mot de passe</label>
    911905</secret>',
  • testapp/modules/jelix_tests/tests/jforms.compiler.html_cli.php

     
    33* @package     testapp
    44* @subpackage  unittest module
    55* @author      Jouanneau Laurent
    6 * @contributor Loic Mathaud
     6* @contributor Loic Mathaud, Julien Issler
    77* @copyright   2007-2008 Jouanneau laurent
    88* @copyright   2007 Loic Mathaud
     9* @copyright   2008 Julien Issler
    910* @link        http://www.jelix.org
    1011* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
    1112*/
     
    700701array('type','checkbox','myfile')
    701702),
    702703array(
    703 '<checkbox ref="nom" xmlns="http://jelix.org/ns/forms/1.0" required="true">
    704     <label>Votre nom</label>
    705 </checkbox>',
    706 'jelix~formserr.attribute.not.allowed',
    707 array('required','checkbox','myfile')
    708 ),
    709 array(
    710704'<secret ref="pwd" defaultvalue="toto"  xmlns="http://jelix.org/ns/forms/1.0">
    711705<label>Votre mot de passe</label>
    712706</secret>',
  • testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

     
    33* @package     testapp
    44* @subpackage  unittest module
    55* @author      Jouanneau Laurent
    6 * @contributor
     6* @contributor Julien Issler
    77* @copyright   2007-2008 Jouanneau laurent
     8* @copyright   2008 Julien Issler
    89* @link        http://www.jelix.org
    910* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
    1011*/
     
    8990        $this->assertTrue($this->form->check());
    9091        $this->form->setData('nom','1');
    9192        $this->assertTrue($this->form->check());
     93       
     94        $ctrl->required = true;
     95        $this->form->setData('nom',null);
     96        $this->assertFalse($this->form->check());
     97        $this->form->setData('nom','');
     98        $this->assertFalse($this->form->check());
     99        $this->form->setData('nom','on');
     100        $this->assertTrue($this->form->check());
     101        $this->form->setData('nom','0');
     102        $this->assertFalse($this->form->check());
     103        $this->form->setData('nom','1');
     104        $this->assertTrue($this->form->check());       
    92105    }
    93106
    94107    function testCheckboxes() {
  • lib/jelix/forms/jFormsCompiler_jf_1_0.class.php

     
    33* @package    jelix
    44* @subpackage forms
    55* @author     Laurent Jouanneau
    6 * @contributor Loic Mathaud, Dominique Papin
     6* @contributor Loic Mathaud, Dominique Papin, Julien Issler
    77* @contributor Uriel Corfa Emotic SARL
    88* @copyright   2006-2008 Laurent Jouanneau
    99* @copyright   2007 Loic Mathaud, 2007 Dominique Papin
    1010* @copyright   2007 Emotic SARL
     11* @copyright   2008 Julien Issler
    1112* @link        http://www.jelix.org
    1213* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
    1314*/
     
    185186            $source[]='$ctrl->valueOnUncheck=\''.str_replace("'","\\'", $attributes['valueonuncheck']) ."';";
    186187            unset($attributes['valueonuncheck']);
    187188        }
     189        $this->attrRequired($source, $attributes);
    188190        return false;
    189191    }
    190192
  • lib/jelix/forms/jFormsControl.class.php

     
    33* @package     jelix
    44* @subpackage  forms
    55* @author      Laurent Jouanneau
    6 * @contributor Loic Mathaud, Dominique Papin
     6* @contributor Loic Mathaud, Dominique Papin, Julien Issler
    77* @copyright   2006-2008 Laurent Jouanneau, 2007 Dominique Papin
    88* @copyright   2007 Loic Mathaud
     9* @copyright   2008 Julien Issler
    910* @link        http://www.jelix.org
    1011* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
    1112*/
     
    222223
    223224    function check(){
    224225        $value = $this->container->data[$this->ref];
     226        if($this->required && $value == $this->valueOnUncheck)
     227            return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED;
    225228        if($value != $this->valueOnCheck && $value != $this->valueOnUncheck)
    226229            return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID;
    227230        return null;
  • lib/jelix/docs/ns/jforms_1.0.rng

     
    126126     <element name="checkbox">
    127127       <ref name="control.common" />
    128128       <ref name="UI.attr.readonly" />
     129       <ref name="UI.attr.required" />
    129130       <ref name="UI.attr.defaultvalue" />
    130131       <optional><attribute name="valueoncheck" /></optional>
    131132       <optional><attribute name="valueonuncheck" /></optional>
  • lib/jelix/docs/ns/jforms_1.1.rng

     
    153153     <element name="checkbox">
    154154       <ref name="control.common" />
    155155       <ref name="UI.attr.readonly" />
     156       <ref name="UI.attr.required" />
    156157       <ref name="UI.attr.defaultvalue" />
    157158       <optional><attribute name="valueoncheck" /></optional>
    158159       <optional><attribute name="valueonuncheck" /></optional>