Changeset 605
- Timestamp:
- 10/05/07 16:07:59 (1 year ago)
- Files:
-
- branches/1.0beta3.x/lib/jelix/forms/jFormsBase.class.php (modified) (1 diff)
- branches/1.0beta3.x/lib/jelix/forms/jFormsBase.class.php (modified) (1 diff)
- branches/1.0beta3.x/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (8 diffs)
- branches/1.0beta3.x/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (8 diffs)
- branches/1.0beta3.x/lib/jelix/forms/jFormsCompiler.class.php (modified) (3 diffs)
- branches/1.0beta3.x/lib/jelix/forms/jFormsCompiler.class.php (modified) (3 diffs)
- branches/1.0beta3.x/lib/jelix/forms/jFormsControl.class.php (modified) (5 diffs)
- branches/1.0beta3.x/lib/jelix/forms/jFormsControl.class.php (modified) (5 diffs)
- branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (4 diffs)
- branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (4 diffs)
- branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.html.php (modified) (4 diffs)
- branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.html.php (modified) (4 diffs)
- branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html.php (modified) (15 diffs)
- branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html.php (modified) (15 diffs)
- branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.with_dao.html.php (modified) (2 diffs)
- branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.with_dao.html.php (modified) (2 diffs)
- branches/1.0beta3.x/testapp/modules/testapp/forms/sample.form.xml (modified) (1 diff)
- branches/1.0beta3.x/testapp/modules/testapp/forms/sample.form.xml (modified) (1 diff)
- trunk/lib/jelix/forms/jFormsBase.class.php (modified) (1 diff)
- trunk/lib/jelix/forms/jFormsBase.class.php (modified) (1 diff)
- trunk/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (8 diffs)
- trunk/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (8 diffs)
- trunk/lib/jelix/forms/jFormsCompiler.class.php (modified) (3 diffs)
- trunk/lib/jelix/forms/jFormsCompiler.class.php (modified) (3 diffs)
- trunk/lib/jelix/forms/jFormsControl.class.php (modified) (5 diffs)
- trunk/lib/jelix/forms/jFormsControl.class.php (modified) (5 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (4 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (4 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.html.php (modified) (4 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.html.php (modified) (4 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html.php (modified) (15 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html.php (modified) (15 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.with_dao.html.php (modified) (2 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.with_dao.html.php (modified) (2 diffs)
- trunk/testapp/modules/testapp/forms/sample.form.xml (modified) (1 diff)
- trunk/testapp/modules/testapp/forms/sample.form.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0beta3.x/lib/jelix/forms/jFormsBase.class.php
r594 r605 502 502 } 503 503 if(!isset($this->_container->datas[$control->ref])){ 504 $this->_container->datas[$control->ref] = $control-> value;504 $this->_container->datas[$control->ref] = $control->defaultValue; 505 505 } 506 506 } branches/1.0beta3.x/lib/jelix/forms/jFormsBase.class.php
r594 r605 502 502 } 503 503 if(!isset($this->_container->datas[$control->ref])){ 504 $this->_container->datas[$control->ref] = $control-> value;504 $this->_container->datas[$control->ref] = $control->defaultValue; 505 505 } 506 506 } branches/1.0beta3.x/lib/jelix/forms/jFormsBuilderBase.class.php
r552 r605 175 175 case 'input': 176 176 $value = $this->_form->getData($ctrl->ref); 177 if($value === null)178 $value = $ctrl->defaultValue;179 177 echo '<input type="text"',$id,$readonly,$hint,$class,' value="',htmlspecialchars($value),'"',$this->_endt; 180 178 break; 181 179 case 'checkbox': 182 180 $value = $this->_form->getData($ctrl->ref); 183 if($value =='')184 $value = $ctrl->defaultValue;185 181 186 182 if($ctrl->valueOnCheck == $value){ … … 196 192 $attrs=' name="'.$ctrl->ref.'[]" id="'.$id; 197 193 $value = $this->_form->getData($ctrl->ref); 198 if($value == null){199 $value = $ctrl->selectedValues;200 }201 194 202 195 if(is_array($value) && count($value) == 1) … … 225 218 $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 226 219 $value = $this->_form->getData($ctrl->ref); 227 if($value === null){ 228 if(count($ctrl->selectedValues) == 1) 229 $value = $ctrl->selectedValues[0]; 220 if(is_array($value)){ 221 if(isset($value[0])) 222 $value = $value[0]; 223 else 224 $value=''; 230 225 } 231 226 foreach($ctrl->datasource->getDatas() as $v=>$label){ … … 238 233 echo '<select',$id,$readonly,$hint,$class,' size="1">'; 239 234 $value = $this->_form->getData($ctrl->ref); 240 if($value === null){ 241 if(count($ctrl->selectedValues) == 1) 242 $value = $ctrl->selectedValues[0]; 243 } 235 if(is_array($value)){ 236 if(isset($value[0])) 237 $value = $value[0]; 238 else 239 $value=''; 240 } 241 244 242 foreach($ctrl->datasource->getDatas() as $v=>$label){ 245 243 echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; … … 251 249 echo '<select name="',$ctrl->ref,'[]" id="',$this->_name,'_',$ctrl->ref,'"',$readonly,$hint,$class,' size="',$ctrl->size,'" multiple="multiple">'; 252 250 $value = $this->_form->getData($ctrl->ref); 253 if($value == null){254 $value = $ctrl->selectedValues;255 }256 251 257 252 if(is_array($value) && count($value) == 1) … … 270 265 }else{ 271 266 $value = $this->_form->getData($ctrl->ref); 272 if($value == null){273 $value = $ctrl->selectedValues;274 }275 267 276 268 if(is_array($value)){ … … 290 282 case 'textarea': 291 283 $value = $this->_form->getData($ctrl->ref); 292 if($value === null)293 $value = $ctrl->defaultValue;294 284 echo '<textarea',$id,$readonly,$hint,$class,'>',htmlspecialchars($value),'</textarea>'; 295 285 break; … … 300 290 case 'output': 301 291 $value = $this->_form->getData($ctrl->ref); 302 if($value === null)303 $value = $ctrl->defaultValue;304 292 echo '<input type="hidden"',$id,' value="',htmlspecialchars($value),'"',$this->_endt; 305 293 echo '<span class="jforms-value"',$hint,'>',htmlspecialchars($value),'</span>'; branches/1.0beta3.x/lib/jelix/forms/jFormsBuilderBase.class.php
r552 r605 175 175 case 'input': 176 176 $value = $this->_form->getData($ctrl->ref); 177 if($value === null)178 $value = $ctrl->defaultValue;179 177 echo '<input type="text"',$id,$readonly,$hint,$class,' value="',htmlspecialchars($value),'"',$this->_endt; 180 178 break; 181 179 case 'checkbox': 182 180 $value = $this->_form->getData($ctrl->ref); 183 if($value =='')184 $value = $ctrl->defaultValue;185 181 186 182 if($ctrl->valueOnCheck == $value){ … … 196 192 $attrs=' name="'.$ctrl->ref.'[]" id="'.$id; 197 193 $value = $this->_form->getData($ctrl->ref); 198 if($value == null){199 $value = $ctrl->selectedValues;200 }201 194 202 195 if(is_array($value) && count($value) == 1) … … 225 218 $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 226 219 $value = $this->_form->getData($ctrl->ref); 227 if($value === null){ 228 if(count($ctrl->selectedValues) == 1) 229 $value = $ctrl->selectedValues[0]; 220 if(is_array($value)){ 221 if(isset($value[0])) 222 $value = $value[0]; 223 else 224 $value=''; 230 225 } 231 226 foreach($ctrl->datasource->getDatas() as $v=>$label){ … … 238 233 echo '<select',$id,$readonly,$hint,$class,' size="1">'; 239 234 $value = $this->_form->getData($ctrl->ref); 240 if($value === null){ 241 if(count($ctrl->selectedValues) == 1) 242 $value = $ctrl->selectedValues[0]; 243 } 235 if(is_array($value)){ 236 if(isset($value[0])) 237 $value = $value[0]; 238 else 239 $value=''; 240 } 241 244 242 foreach($ctrl->datasource->getDatas() as $v=>$label){ 245 243 echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; … … 251 249 echo '<select name="',$ctrl->ref,'[]" id="',$this->_name,'_',$ctrl->ref,'"',$readonly,$hint,$class,' size="',$ctrl->size,'" multiple="multiple">'; 252 250 $value = $this->_form->getData($ctrl->ref); 253 if($value == null){254 $value = $ctrl->selectedValues;255 }256 251 257 252 if(is_array($value) && count($value) == 1) … … 270 265 }else{ 271 266 $value = $this->_form->getData($ctrl->ref); 272 if($value == null){273 $value = $ctrl->selectedValues;274 }275 267 276 268 if(is_array($value)){ … … 290 282 case 'textarea': 291 283 $value = $this->_form->getData($ctrl->ref); 292 if($value === null)293 $value = $ctrl->defaultValue;294 284 echo '<textarea',$id,$readonly,$hint,$class,'>',htmlspecialchars($value),'</textarea>'; 295 285 break; … … 300 290 case 'output': 301 291 $value = $this->_form->getData($ctrl->ref); 302 if($value === null)303 $value = $ctrl->defaultValue;304 292 echo '<input type="hidden"',$id,' value="',htmlspecialchars($value),'"',$this->_endt; 305 293 echo '<span class="jforms-value"',$hint,'>',htmlspecialchars($value),'</span>'; branches/1.0beta3.x/lib/jelix/forms/jFormsCompiler.class.php
r580 r605 210 210 $str.="'". str_replace("'","\\'", (string)$value) ."',"; 211 211 } 212 $source[]='$ctrl-> selectedValues='.$str.');';212 $source[]='$ctrl->defaultValue='.$str.');'; 213 213 $hasSelectedValues = true; 214 214 }elseif(isset($control['selectedvalue'])){ 215 $source[]='$ctrl-> selectedValues=array(\''. str_replace("'","\\'", (string)$control['selectedvalue']) .'\');';215 $source[]='$ctrl->defaultValue=array(\''. str_replace("'","\\'", (string)$control['selectedvalue']) .'\');'; 216 216 $hasSelectedValues = true; 217 217 } … … 264 264 throw new jException('jelix~formserr.multiple.selected.not.allowed',$this->sourceFile); 265 265 } 266 $source[]='$ctrl-> selectedValues='.var_export($selectedvalues,true).';';266 $source[]='$ctrl->defaultValue='.var_export($selectedvalues,true).';'; 267 267 } 268 268 }else{ … … 290 290 if($alertRequired!='') 291 291 $source[]='$ctrl2->alertRequired = $ctrl->alertRequired;'; 292 292 293 293 if(isset($control->help)){ 294 294 $source[]='$ctrl2->hasHelp=true;'; branches/1.0beta3.x/lib/jelix/forms/jFormsCompiler.class.php
r580 r605 210 210 $str.="'". str_replace("'","\\'", (string)$value) ."',"; 211 211 } 212 $source[]='$ctrl-> selectedValues='.$str.');';212 $source[]='$ctrl->defaultValue='.$str.');'; 213 213 $hasSelectedValues = true; 214 214 }elseif(isset($control['selectedvalue'])){ 215 $source[]='$ctrl-> selectedValues=array(\''. str_replace("'","\\'", (string)$control['selectedvalue']) .'\');';215 $source[]='$ctrl->defaultValue=array(\''. str_replace("'","\\'", (string)$control['selectedvalue']) .'\');'; 216 216 $hasSelectedValues = true; 217 217 } … … 264 264 throw new jException('jelix~formserr.multiple.selected.not.allowed',$this->sourceFile); 265 265 } 266 $source[]='$ctrl-> selectedValues='.var_export($selectedvalues,true).';';266 $source[]='$ctrl->defaultValue='.var_export($selectedvalues,true).';'; 267 267 } 268 268 }else{ … … 290 290 if($alertRequired!='') 291 291 $source[]='$ctrl2->alertRequired = $ctrl->alertRequired;'; 292 292 293 293 if(isset($control->help)){ 294 294 $source[]='$ctrl2->hasHelp=true;'; branches/1.0beta3.x/lib/jelix/forms/jFormsControl.class.php
r552 r605 28 28 public $readonly = false; 29 29 public $label=''; 30 public $ value='';30 public $defaultValue=''; 31 31 public $hasHelp = false; 32 32 public $hint=''; … … 71 71 */ 72 72 public $datasource; 73 public $ selectedValues=array();73 public $defaultValue=array(); 74 74 75 75 function getDisplayValue($value){ … … 93 93 class jFormsControlInput extends jFormsControl { 94 94 public $type='input'; 95 public $defaultValue='';96 95 } 97 96 … … 195 194 class jFormsControlTextarea extends jFormsControl { 196 195 public $type='textarea'; 197 public $defaultValue='';198 196 } 199 197 … … 247 245 class jFormsControlOutput extends jFormsControl { 248 246 public $type='output'; 249 public $defaultValue='';250 247 251 248 public function check($value, $form){ branches/1.0beta3.x/lib/jelix/forms/jFormsControl.class.php
r552 r605 28 28 public $readonly = false; 29 29 public $label=''; 30 public $ value='';30 public $defaultValue=''; 31 31 public $hasHelp = false; 32 32 public $hint=''; … … 71 71 */ 72 72 public $datasource; 73 public $ selectedValues=array();73 public $defaultValue=array(); 74 74 75 75 function getDisplayValue($value){ … … 93 93 class jFormsControlInput extends jFormsControl { 94 94 public $type='input'; 95 public $defaultValue='';96 95 } 97 96 … … 195 194 class jFormsControlTextarea extends jFormsControl { 196 195 public $type='textarea'; 197 public $defaultValue='';198 196 } 199 197 … … 247 245 class jFormsControlOutput extends jFormsControl { 248 246 public $type='output'; 249 public $defaultValue='';250 247 251 248 public function check($value, $form){ branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.compiler.html.php
r580 r605 422 422 \'ccc\'=>\'ccc\', 423 423 ); 424 $ctrl-> selectedValues=array (424 $ctrl->defaultValue=array ( 425 425 0 => \'aaa\', 426 426 ); … … 434 434 \'ccc\'=>\'ccc\', 435 435 ); 436 $ctrl-> selectedValues=array (436 $ctrl->defaultValue=array ( 437 437 0 => \'aaa\', 438 438 1 => \'ccc\', … … 442 442 40=>'$ctrl= new jFormsControllistbox(\'nom\'); 443 443 $ctrl->label=\'Votre nom\'; 444 $ctrl-> selectedValues=array(\'aaa\');444 $ctrl->defaultValue=array(\'aaa\'); 445 445 $ctrl->datasource= new jFormStaticDatasource(); 446 446 $ctrl->datasource->datas = array( … … 453 453 41=>'$ctrl= new jFormsControllistbox(\'nom\'); 454 454 $ctrl->label=\'Votre nom\'; 455 $ctrl-> selectedValues= array(\'bbb\',\'aaa\',);455 $ctrl->defaultValue= array(\'bbb\',\'aaa\',); 456 456 $ctrl->datasource= new jFormStaticDatasource(); 457 457 $ctrl->datasource->datas = array( branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.compiler.html.php
r580 r605 422 422 \'ccc\'=>\'ccc\', 423 423 ); 424 $ctrl-> selectedValues=array (424 $ctrl->defaultValue=array ( 425 425 0 => \'aaa\', 426 426 ); … … 434 434 \'ccc\'=>\'ccc\', 435 435 ); 436 $ctrl-> selectedValues=array (436 $ctrl->defaultValue=array ( 437 437 0 => \'aaa\', 438 438 1 => \'ccc\', … … 442 442 40=>'$ctrl= new jFormsControllistbox(\'nom\'); 443 443 $ctrl->label=\'Votre nom\'; 444 $ctrl-> selectedValues=array(\'aaa\');444 $ctrl->defaultValue=array(\'aaa\'); 445 445 $ctrl->datasource= new jFormStaticDatasource(); 446 446 $ctrl->datasource->datas = array( … … 453 453 41=>'$ctrl= new jFormsControllistbox(\'nom\'); 454 454 $ctrl->label=\'Votre nom\'; 455 $ctrl-> selectedValues= array(\'bbb\',\'aaa\',);455 $ctrl->defaultValue= array(\'bbb\',\'aaa\',); 456 456 $ctrl->datasource= new jFormStaticDatasource(); 457 457 $ctrl->datasource->datas = array( branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.html.php
r483 r605 42 42 <boolean property="readonly" value="false"/> 43 43 <string property="label" value="product name"/> 44 <string property=" value" value=""/>45 </object> 46 <object key="price" class="jFormsControlInput"> 47 <string property="ref" value="price"/> 48 <boolean property="required" value="false"/> 49 <boolean property="readonly" value="false"/> 50 <string property="label" value="The price"/> 51 <string property=" value" value=""/>44 <string property="defaultValue" value=""/> 45 </object> 46 <object key="price" class="jFormsControlInput"> 47 <string property="ref" value="price"/> 48 <boolean property="required" value="false"/> 49 <boolean property="readonly" value="false"/> 50 <string property="label" value="The price"/> 51 <string property="defaultValue" value=""/> 52 52 </object> 53 53 </array> … … 77 77 <boolean property="readonly" value="false"/> 78 78 <string property="label" value="product name"/> 79 <string property=" value" value=""/>80 </object> 81 <object key="price" class="jFormsControlInput"> 82 <string property="ref" value="price"/> 83 <boolean property="required" value="false"/> 84 <boolean property="readonly" value="false"/> 85 <string property="label" value="The price"/> 86 <string property=" value" value=""/>79 <string property="defaultValue" value=""/> 80 </object> 81 <object key="price" class="jFormsControlInput"> 82 <string property="ref" value="price"/> 83 <boolean property="required" value="false"/> 84 <boolean property="readonly" value="false"/> 85 <string property="label" value="The price"/> 86 <string property="defaultValue" value=""/> 87 87 </object> 88 88 </array> … … 186 186 <boolean property="readonly" value="false"/> 187 187 <string property="label" value="product name"/> 188 <string property=" value" value=""/>189 </object> 190 <object key="price" class="jFormsControlInput"> 191 <string property="ref" value="price"/> 192 <boolean property="required" value="false"/> 193 <boolean property="readonly" value="false"/> 194 <string property="label" value="The price"/> 195 <string property=" value" value=""/>188 <string property="defaultValue" value=""/> 189 </object> 190 <object key="price" class="jFormsControlInput"> 191 <string property="ref" value="price"/> 192 <boolean property="required" value="false"/> 193 <boolean property="readonly" value="false"/> 194 <string property="label" value="The price"/> 195 <string property="defaultValue" value=""/> 196 196 </object> 197 197 </array> … … 226 226 <boolean property="readonly" value="false"/> 227 227 <string property="label" value="product name"/> 228 <string property=" value" value=""/>229 </object> 230 <object key="price" class="jFormsControlInput"> 231 <string property="ref" value="price"/> 232 <boolean property="required" value="false"/> 233 <boolean property="readonly" value="false"/> 234 <string property="label" value="The price"/> 235 <string property=" value" value=""/>228 <string property="defaultValue" value=""/> 229 </object> 230 <object key="price" class="jFormsControlInput"> 231 <string property="ref" value="price"/> 232 <boolean property="required" value="false"/> 233 <boolean property="readonly" value="false"/> 234 <string property="label" value="The price"/> 235 <string property="defaultValue" value=""/> 236 236 </object> 237 237 </array> branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.html.php
r483 r605 42 42 <boolean property="readonly" value="false"/> 43 43 <string property="label" value="product name"/> 44 <string property=" value" value=""/>45 </object> 46 <object key="price" class="jFormsControlInput"> 47 <string property="ref" value="price"/> 48 <boolean property="required" value="false"/> 49 <boolean property="readonly" value="false"/> 50 <string property="label" value="The price"/> 51 <string property=" value" value=""/>44 <string property="defaultValue" value=""/> 45 </object> 46 <object key="price" class="jFormsControlInput"> 47 <string property="ref" value="price"/> 48 <boolean property="required" value="false"/> 49 <boolean property="readonly" value="false"/> 50 <string property="label" value="The price"/> 51 <string property="defaultValue" value=""/> 52 52 </object> 53 53 </array> … … 77 77 <boolean property="readonly" value="false"/> 78 78 <string property="label" value="product name"/> 79 <string property=" value" value=""/>80 </object> 81 <object key="price" class="jFormsControlInput"> 82 <string property="ref" value="price"/> 83 <boolean property="required" value="false"/> 84 <boolean property="readonly" value="false"/> 85 <string property="label" value="The price"/> 86 <string property=" value" value=""/>79 <string property="defaultValue" value=""/> 80 </object> 81 <object key="price" class="jFormsControlInput"> 82 <string property="ref" value="price"/> 83 <boolean property="required" value="false"/> 84 <boolean property="readonly" value="false"/> 85 <string property="label" value="The price"/> 86 <string property="defaultValue" value=""/> 87 87 </object> 88 88 </array> … … 186 186 <boolean property="readonly" value="false"/> 187 187 <string property="label" value="product name"/> 188 <string property=" value" value=""/>189 </object> 190 <object key="price" class="jFormsControlInput"> 191 <string property="ref" value="price"/> 192 <boolean property="required" value="false"/> 193 <boolean property="readonly" value="false"/> 194 <string property="label" value="The price"/> 195 <string property=" value" value=""/>188 <string property="defaultValue" value=""/> 189 </object> 190 <object key="price" class="jFormsControlInput"> 191 <string property="ref" value="price"/> 192 <boolean property="required" value="false"/> 193 <boolean property="readonly" value="false"/> 194 <string property="label" value="The price"/> 195 <string property="defaultValue" value=""/> 196 196 </object> 197 197 </array> … … 226 226 <boolean property="readonly" value="false"/> 227 227 <string property="label" value="product name"/> 228 <string property=" value" value=""/>229 </object> 230 <object key="price" class="jFormsControlInput"> 231 <string property="ref" value="price"/> 232 <boolean property="required" value="false"/> 233 <boolean property="readonly" value="false"/> 234 <string property="label" value="The price"/> 235 <string property=" value" value=""/>228 <string property="defaultValue" value=""/> 229 </object> 230 <object key="price" class="jFormsControlInput"> 231 <string property="ref" value="price"/> 232 <boolean property="required" value="false"/> 233 <boolean property="readonly" value="false"/> 234 <string property="label" value="The price"/> 235 <string property="defaultValue" value=""/> 236 236 </object> 237 237 </array> branches/1.0beta3.x/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html.php
r556 r605 18 18 class testHMLForm { // simulate a jFormBase object 19 19 public $controls= array(); 20 public $submits= array(); 21 public $uploads= array(); 20 22 public $container; 21 23 24 protected $datas = array( 'chk'=>'1', 'chk2'=>'', 'choixsimple'=>'11', 'choixmultiple'=>array('10','23')); 22 25 function __construct(){ 23 26 $this->container = new jFormsDataContainer('',''); … … 25 28 26 29 function getData($name) { 27 $a = array('nom'=>'laurent', 'chk'=>'1', 'chk2'=>'', 'chk3'=>'0', 'choixsimple'=>'11', 'choixmultiple'=>array('10','23')); 28 if(isset($a[$name])) 29 return $a[$name]; 30 if(isset($this->datas[$name])) 31 return $this->datas[$name]; 30 32 else 31 33 return null; 32 34 } 35 function setData($name,$value) { 36 $this->datas[$name]=$value; 37 } 33 38 function getControls() { 34 39 return $this->controls; … … 39 44 function hasUpload(){ 40 45 return false; 46 } 47 function addControl($control){ 48 $this->controls [$control->ref] = $control; 49 if($control->type =='submit') 50 $this->submits [$control->ref] = $control; 51 if($control->type =='upload'){ 52 $this->uploads [$control->ref] = $control; 53 } 54 $this->datas[$control->ref] = $control->defaultValue; 41 55 } 42 56 } … … 51 65 class UTjformsHTMLBuilder extends jUnitTestCaseDb { 52 66 67 protected $form; 53 68 protected $builder; 54 69 function testStart() { 55 $ form = new testHMLForm();56 $this->builder = new testJFormsHtmlBuilder($ form, 'jelix_tests~urlsig_url1',array());70 $this->form = new testHMLForm(); 71 $this->builder = new testJFormsHtmlBuilder($this->form, 'jelix_tests~urlsig_url1',array()); 57 72 $this->formname = $this->builder->getName(); 58 73 } … … 105 120 106 121 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 122 $this->assertEqualOrDiff('<input type="text" name="nom" id="'.$this->formname.'_nom" value=""/>', $out); 123 124 $this->form->addControl($ctrl); 125 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 126 $this->assertEqualOrDiff('<input type="text" name="nom" id="'.$this->formname.'_nom" value=""/>', $out); 127 128 $this->form->setData('nom','toto'); 129 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 130 $this->assertEqualOrDiff('<input type="text" name="nom" id="'.$this->formname.'_nom" value="toto"/>', $out); 131 132 $ctrl->defaultValue='laurent'; 133 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 134 $this->assertEqualOrDiff('<input type="text" name="nom" id="'.$this->formname.'_nom" value="toto"/>', $out); 135 136 $this->form->addControl($ctrl); 137 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 107 138 $this->assertEqualOrDiff('<input type="text" name="nom" id="'.$this->formname.'_nom" value="laurent"/>', $out); 108 139 … … 111 142 $this->assertEqualOrDiff('<input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" value="laurent"/>', $out); 112 143 113 $ctrl= new jFormsControlinput('nominconnu'); 114 $ctrl->datatype= new jDatatypeString(); 115 $ctrl->label='Votre nom'; 116 $ctrl->defaultValue='toto'; 117 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 118 $this->assertEqualOrDiff('<input type="text" name="nominconnu" id="'.$this->formname.'_nominconnu" value="toto"/>', $out); 119 144 $ctrl->readonly=false; 120 145 $ctrl->hasHelp=true; 121 146 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 122 $this->assertEqualOrDiff('<input type="text" name="nom inconnu" id="'.$this->formname.'_nominconnu" value="toto"/><span class="jforms-help"><a href="javascript:jForms.showHelp(\''. $this->formname.'\',\'nominconnu\')">?</a></span>', $out);123 124 $ctrl->hint='ceci est un tooltip'; 125 ob_start();$this->builder->outputControlLabel($ctrl);$out = ob_get_clean(); 126 $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_nom inconnu" title="ceci est un tooltip">Votre nom</label>', $out);127 128 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 129 $this->assertEqualOrDiff('<input type="text" name="nom inconnu" id="'.$this->formname.'_nominconnu" title="ceci est un tooltip" value="toto"/><span class="jforms-help"><a href="javascript:jForms.showHelp(\''. $this->formname.'\',\'nominconnu\')">?</a></span>', $out);147 $this->assertEqualOrDiff('<input type="text" name="nom" id="'.$this->formname.'_nom" value="laurent"/><span class="jforms-help"><a href="javascript:jForms.showHelp(\''. $this->formname.'\',\'nom\')">?</a></span>', $out); 148 149 $ctrl->hint='ceci est un tooltip'; 150 ob_start();$this->builder->outputControlLabel($ctrl);$out = ob_get_clean(); 151 $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_nom" title="ceci est un tooltip">Votre nom</label>', $out); 152 153 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 154 $this->assertEqualOrDiff('<input type="text" name="nom" id="'.$this->formname.'_nom" title="ceci est un tooltip" value="laurent"/><span class="jforms-help"><a href="javascript:jForms.showHelp(\''. $this->formname.'\',\'nom\')">?</a></span>', $out); 130 155 131 156 } … … 134 159 $ctrl->datatype= new jDatatypeString(); 135 160 $ctrl->label='Une option'; 161 $this->form->addControl($ctrl); 136 162 137 163 ob_start();$this->builder->outputControlLabel($ctrl);$out = ob_get_clean(); … … 139 165 140 166 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 167 $this->assertEqualOrDiff('<input type="checkbox" name="chk" id="'.$this->formname.'_chk" value="1"/>', $out); 168 169 $this->form->setData('chk','1'); 170 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 141 171 $this->assertEqualOrDiff('<input type="checkbox" name="chk" id="'.$this->formname.'_chk" checked="checked" value="1"/>', $out); 142 172 … … 152 182 153 183 $ctrl->defaultValue='1'; 184 $this->form->addControl($ctrl); 154 185 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 155 186 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" checked="checked" value="1"/>', $out); 156 187 157 158 $ctrl= new jFormsControlCheckbox('chk3'); 159 $ctrl->datatype= new jDatatypeString(); 160 $ctrl->label='Une option'; 161 162 ob_start();$this->builder->outputControlLabel($ctrl);$out = ob_get_clean(); 163 $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_chk3">Une option</label>', $out); 164 165 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 166 $this->assertEqualOrDiff('<input type="checkbox" name="chk3" id="'.$this->formname.'_chk3" value="1"/>', $out); 167 168 $ctrl->defaultValue='1'; 169 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 170 $this->assertEqualOrDiff('<input type="checkbox" name="chk3" id="'.$this->formname.'_chk3" value="1"/>', $out); 171 172 173 $ctrl= new jFormsControlCheckbox('chkinconnu'); 174 $ctrl->datatype= new jDatatypeString(); 175 $ctrl->label='Une option'; 176 177 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 178 $this->assertEqualOrDiff('<input type="checkbox" name="chkinconnu" id="'.$this->formname.'_chkinconnu" value="1"/>', $out); 188 $this->form->setData('chk2', '0'); 189 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 190 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" value="1"/>', $out); 179 191 180 192 $ctrl->readonly=true; 181 193 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 182 $this->assertEqualOrDiff('<input type="checkbox" name="chkinconnu" id="'.$this->formname.'_chkinconnu" readonly="readonly" value="1"/>', $out); 183 184 $ctrl->defaultValue='1'; 185 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 186 $this->assertEqualOrDiff('<input type="checkbox" name="chkinconnu" id="'.$this->formname.'_chkinconnu" readonly="readonly" checked="checked" value="1"/>', $out); 187 188 189 $ctrl->hint='ceci est un tooltip'; 190 ob_start();$this->builder->outputControlLabel($ctrl);$out = ob_get_clean(); 191 $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_chkinconnu" title="ceci est un tooltip">Une option</label>', $out); 192 193 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 194 $this->assertEqualOrDiff('<input type="checkbox" name="chkinconnu" id="'.$this->formname.'_chkinconnu" readonly="readonly" title="ceci est un tooltip" checked="checked" value="1"/>', $out); 195 196 197 } 194 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" value="1"/>', $out); 195 196 $this->form->setData('chk2', '1'); 197 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 198 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" checked="checked" value="1"/>', $out); 199 200 $ctrl->hint='ceci est un tooltip'; 201 ob_start();$this->builder->outputControlLabel($ctrl);$out
