Changeset 650

Show
Ignore:
Timestamp:
11/22/07 22:25:30 (1 year ago)
Author:
laurentj
Message:

worked on ticket #251: add support of minlength and maxlength in jforms

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix-scripts/commands/createform.cmd.php

    r641 r650  
    8888            if($property->required) 
    8989                $attr.=' required="true"'; 
    90                  
     90 
    9191            if($property->defaultValue !== null) 
    9292                $attr.=' defaultvalue="'.htmlspecialchars($property->defaultValue).'"'; 
    93              
     93 
     94            if($property->maxlength !== null) 
     95                $attr.=' maxlength="'.$property->maxlength.'"'; 
     96 
     97            if($property->minlength !== null) 
     98                $attr.=' minlength="'.$property->minlength.'"'; 
     99 
    94100            //if(false) 
    95101            //    $attr.=' defaultvalue=""'; 
  • trunk/lib/jelix-scripts/commands/createform.cmd.php

    r641 r650  
    8888            if($property->required) 
    8989                $attr.=' required="true"'; 
    90                  
     90 
    9191            if($property->defaultValue !== null) 
    9292                $attr.=' defaultvalue="'.htmlspecialchars($property->defaultValue).'"'; 
    93              
     93 
     94            if($property->maxlength !== null) 
     95                $attr.=' maxlength="'.$property->maxlength.'"'; 
     96 
     97            if($property->minlength !== null) 
     98                $attr.=' minlength="'.$property->minlength.'"'; 
     99 
    94100            //if(false) 
    95101            //    $attr.=' defaultvalue=""'; 
  • trunk/lib/jelix-www/js/jforms.js

    r647 r650  
    308308    this.isConfirmField = false; 
    309309    this.confirmFieldOf = ''; 
     310    this.minLength = -1; 
     311    this.maxLength = -1; 
    310312} 
    311313 
  • trunk/lib/jelix-www/js/jforms.js

    r647 r650  
    308308    this.isConfirmField = false; 
    309309    this.confirmFieldOf = ''; 
     310    this.minLength = -1; 
     311    this.maxLength = -1; 
    310312} 
    311313 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r632 r650  
    142142            } 
    143143            $source[]='$ctrl->defaultValue=\''.str_replace('\'','\\\'',(string)$control['defaultvalue']) .'\';'; 
     144        } 
     145        // minlength support 
     146        if(isset($control['minlength'])){ 
     147            if($controltype != 'textarea' &&  
     148                ($controltype != 'input'|| ($controltype == 'input' && isset($control['type']) && $control['type'] != 'string'))){ 
     149                throw new jException('jelix~formserr.attribute.not.allowed',array('minlength',$controltype,$this->sourceFile)); 
     150            } 
     151            $source[]='$ctrl->datasource->addFacet(\'minLength\','.intval((string)$control['minlength']).');'; 
     152        } 
     153        // maxlength support 
     154        if(isset($control['maxlength'])){ 
     155            if($controltype != 'textarea' &&  
     156                ($controltype != 'input'|| ($controltype == 'input' && isset($control['type']) && $control['type'] != 'string'))){ 
     157                throw new jException('jelix~formserr.attribute.not.allowed',array('maxlength',$controltype,$this->sourceFile)); 
     158            } 
     159            $source[]='$ctrl->datasource->addFacet(\'maxLength\','.intval((string)$control['maxlength']).');'; 
    144160        } 
    145161 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r632 r650  
    142142            } 
    143143            $source[]='$ctrl->defaultValue=\''.str_replace('\'','\\\'',(string)$control['defaultvalue']) .'\';'; 
     144        } 
     145        // minlength support 
     146        if(isset($control['minlength'])){ 
     147            if($controltype != 'textarea' &&  
     148                ($controltype != 'input'|| ($controltype == 'input' && isset($control['type']) && $control['type'] != 'string'))){ 
     149                throw new jException('jelix~formserr.attribute.not.allowed',array('minlength',$controltype,$this->sourceFile)); 
     150            } 
     151            $source[]='$ctrl->datasource->addFacet(\'minLength\','.intval((string)$control['minlength']).');'; 
     152        } 
     153        // maxlength support 
     154        if(isset($control['maxlength'])){ 
     155            if($controltype != 'textarea' &&  
     156                ($controltype != 'input'|| ($controltype == 'input' && isset($control['type']) && $control['type'] != 'string'))){ 
     157                throw new jException('jelix~formserr.attribute.not.allowed',array('maxlength',$controltype,$this->sourceFile)); 
     158            } 
     159            $source[]='$ctrl->datasource->addFacet(\'maxLength\','.intval((string)$control['maxlength']).');'; 
    144160        } 
    145161 
  • trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php

    r632 r650  
    26626664=>'<textarea ref="nom" rows="15" cols="20" xmlns="http://jelix.org/ns/forms/1.0"> 
    267267    <label>Votre nom</label> 
    268 </textarea>' 
     268</textarea>', 
     26965=>'<input ref="nom" maxlength="3" xmlns="http://jelix.org/ns/forms/1.0"> 
     270    <label>Votre nom</label> 
     271</input>', 
    269272    ); 
    270273 
     
    614617$ctrl->rows=15; 
    615618$ctrl->cols=20; 
    616 $this->addControl($ctrl);' 
     619$this->addControl($ctrl);', 
     62065=>'$ctrl= new jFormsControlinput(\'nom\'); 
     621$ctrl->datasource->addFacet(\'maxLength\',3); 
     622$ctrl->label=\'Votre nom\'; 
     623$this->addControl($ctrl);', 
    617624); 
    618625 
     
    959966$js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 
    960967$js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n"; 
    961 $js.="jForms.tForm.addControl( jForms.tControl);\n";' 
     968$js.="jForms.tForm.addControl( jForms.tControl);\n";', 
     96965=>'$label = \'Votre nom\'; 
     970$js.="jForms.tControl = new jFormsControl(\'nom\', \'".str_replace("\'","\\\'",$label)."\', \'string\');\n"; 
     971$js.="jForms.tControl.maxLength = 3;\n"; 
     972$js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 
     973$js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n"; 
     974$js.="jForms.tForm.addControl( jForms.tControl);\n";', 
    962975    ); 
    963976 
  • trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php

    r632 r650  
    26626664=>'<textarea ref="nom" rows="15" cols="20" xmlns="http://jelix.org/ns/forms/1.0"> 
    267267    <label>Votre nom</label> 
    268 </textarea>' 
     268</textarea>', 
     26965=>'<input ref="nom" maxlength="3" xmlns="http://jelix.org/ns/forms/1.0"> 
     270    <label>Votre nom</label> 
     271</input>', 
    269272    ); 
    270273 
     
    614617$ctrl->rows=15; 
    615618$ctrl->cols=20; 
    616 $this->addControl($ctrl);' 
     619$this->addControl($ctrl);', 
     62065=>'$ctrl= new jFormsControlinput(\'nom\'); 
     621$ctrl->datasource->addFacet(\'maxLength\',3); 
     622$ctrl->label=\'Votre nom\'; 
     623$this->addControl($ctrl);', 
    617624); 
    618625 
     
    959966$js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 
    960967$js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n"; 
    961 $js.="jForms.tForm.addControl( jForms.tControl);\n";' 
     968$js.="jForms.tForm.addControl( jForms.tControl);\n";', 
     96965=>'$label = \'Votre nom\'; 
     970$js.="jForms.tControl = new jFormsControl(\'nom\', \'".str_replace("\'","\\\'",$label)."\', \'string\');\n"; 
     971$js.="jForms.tControl.maxLength = 3;\n"; 
     972$js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 
     973$js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n"; 
     974$js.="jForms.tForm.addControl( jForms.tControl);\n";', 
    962975    ); 
    963976 
Download in other formats: Unified Diff Zip Archive