Changeset 1063

Show
Ignore:
Timestamp:
08/26/08 00:29:07 (3 months ago)
Author:
laurentj
Message:

ticket #556: jforms, added support of minlength and maxlength on secret control

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/docs/ns/jforms_1.1.rng

    r1062 r1063  
    118118       <ref name="UI.attr.readonly" /> 
    119119       <ref name="UI.attr.required" /> 
     120       <ref name="attr.length" /> 
    120121       <ref name="attr.size" /> 
    121122       <optional> 
  • trunk/lib/jelix/forms/jFormsCompiler_jf_1_1.class.php

    r1053 r1063  
    8383    } 
    8484 
     85    protected function generateSecret(&$source, $control, &$attributes) { 
     86        if(isset($attributes['minlength'])){ 
     87            $source[]='$ctrl->datatype->addFacet(\'minLength\','.intval($attributes['minlength']).');'; 
     88            unset($attributes['minlength']); 
     89        } 
     90        if(isset($attributes['maxlength'])){ 
     91            $source[]='$ctrl->datatype->addFacet(\'maxLength\','.intval($attributes['maxlength']).');'; 
     92            unset($attributes['maxlength']); 
     93        } 
     94        return parent::generateSecret($source, $control, $attributes); 
     95    } 
     96 
    8597    protected function generateHtmleditor(&$source, $control, &$attributes) { 
    8698        $this->_generateTextareaHtmlEditor($source, $control, $attributes); 
  • trunk/lib/jelix/forms/jFormsControl.class.php

    r1053 r1063  
    180180    public $size=0; 
    181181 
    182     function check(){ 
    183         if ($this->container->data[$this->ref] == '' && $this->required) { 
    184             return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED; 
    185         } 
    186         return null; 
    187     } 
    188182    function getDisplayValue($value){ 
    189183        return str_repeat("*", strlen($value)); 
  • trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

    r1053 r1063  
    445445    protected function outputSecret($ctrl, $id, $class, $readonly, $hint) { 
    446446        $size = ($ctrl->size == 0?'': ' size="'.$ctrl->size.'"'); 
    447         echo '<input type="password"',$id,$readonly,$hint,$class,$size,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt; 
     447        $maxl = $ctrl->datatype->getFacet('maxLength'); 
     448        if($maxl !== null) 
     449            $maxl = ' maxlength="'.$maxl.'"'; 
     450        else 
     451            $maxl = ''; 
     452        echo '<input type="password"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt; 
    448453    } 
    449454 
  • trunk/testapp/modules/jelix_tests/tests/jforms.compiler_1_1.html_cli.php

    r1062 r1063  
    375375    <datasource dao="foo" method="bar" labelproperty="baz,biz" labelseparator=" - " valueproperty="plop" criteriafrom="prenom,nom"/> 
    376376</menulist>', 
    377  
     37783=>'<secret ref="pwd" minlength="5" maxlength="10" xmlns="http://jelix.org/ns/forms/1.1"> 
     378    <label>Votre mot de passe</label> 
     379    <confirm>confirmez</confirm> 
     380</secret>', 
    378381    ); 
    379382 
     
    828831$ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz,biz\',\'plop\',\'\',null,\'prenom,nom\',\' - \'); 
    829832$this->addControl($ctrl);', 
     83383=>'$ctrl= new jFormsControlsecret(\'pwd\'); 
     834$ctrl->datatype->addFacet(\'minLength\',5); 
     835$ctrl->datatype->addFacet(\'maxLength\',10); 
     836$ctrl->label=\'Votre mot de passe\'; 
     837$ctrl2 = new jFormsControlSecretConfirm(\'pwd_confirm\'); 
     838$ctrl2->primarySecret = \'pwd\'; 
     839$ctrl2->label=\'confirmez\'; 
     840$ctrl2->required = $ctrl->required; 
     841$this->addControl($ctrl); 
     842$this->addControl($ctrl2);', 
    830843); 
    831844 
  • trunk/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html_cli.php

    r1050 r1063  
    10031003jForms.tForm.addControl(jForms.tControl); 
    10041004', $this->builder->getJsContent()); 
     1005 
     1006        $ctrl->datatype->addFacet('minLength',5); 
     1007        $ctrl->datatype->addFacet('maxLength',10); 
     1008        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
     1009        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" maxlength="10" value="laurent"/>', $out); 
     1010        $this->assertEqualOrDiff('jForms.tControl = new jFormsControlString(\'passwd\', \'mot de passe\'); 
     1011jForms.tControl.maxLength = \'10\'; 
     1012jForms.tControl.minLength = \'5\'; 
     1013jForms.tControl.errInvalid=\'La saisie de "mot de passe" est invalide\'; 
     1014jForms.tForm.addControl(jForms.tControl); 
     1015', $this->builder->getJsContent()); 
     1016 
    10051017 
    10061018    } 
Download in other formats: Unified Diff Zip Archive