Changeset 540
- Timestamp:
- 08/26/07 23:08:46 (1 year ago)
- Files:
-
- trunk/lib/jelix-www/js/jforms.js (modified) (5 diffs)
- trunk/lib/jelix-www/js/jforms.js (modified) (5 diffs)
- trunk/lib/jelix/docs/ns/jforms-controls.rng (modified) (5 diffs)
- trunk/lib/jelix/docs/ns/jforms-controls.rng (modified) (5 diffs)
- trunk/lib/jelix/forms/jFormsBase.class.php (modified) (3 diffs)
- trunk/lib/jelix/forms/jFormsBase.class.php (modified) (3 diffs)
- trunk/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (1 diff)
- trunk/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (1 diff)
- trunk/lib/jelix/forms/jFormsCompiler.class.php (modified) (16 diffs)
- trunk/lib/jelix/forms/jFormsCompiler.class.php (modified) (16 diffs)
- trunk/lib/jelix/forms/jFormsControl.class.php (modified) (8 diffs)
- trunk/lib/jelix/forms/jFormsControl.class.php (modified) (8 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.check_datas.html.php (modified) (7 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.check_datas.html.php (modified) (7 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (16 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (16 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html.php (modified) (1 diff)
- 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
trunk/lib/jelix-www/js/jforms.js
r530 r540 13 13 usage : 14 14 15 gForm = new jFormsForm('name'); // create a form descriptor16 gForm.setErrorDecorator(new jFormsErrorDecoratorAlert()); // declare an error handler15 jForms.tForm = new jFormsForm('name'); // create a form descriptor 16 jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorAlert()); // declare an error handler 17 17 18 18 // declare a form control 19 gControl = new jFormsControl('name', 'a label', 'datatype');20 gControl.required = true;21 gControl.errInvalid='';22 gControl.errRequired='';23 gForm.addControl( gControl);19 jForms.tControl = new jFormsControl('name', 'a label', 'datatype'); 20 jForms.tControl.required = true; 21 jForms.tControl.errInvalid=''; 22 jForms.tControl.errRequired=''; 23 jForms.tForm.addControl( gControl); 24 24 ... 25 25 26 26 // declare the form now 27 jForms.declareForm( gForm);27 jForms.declareForm(jForms.tForm); 28 28 29 29 On a form tag : … … 32 32 */ 33 33 34 35 var gForm, gControl;36 37 34 /* 38 35 … … 40 37 var jForms = { 41 38 _forms: {}, 39 40 tForm: null, 41 tControl: null, 42 tControl2: null, 42 43 43 44 declareForm : function(aForm){ … … 202 203 } 203 204 } 205 if(c.isConfirmField){ 206 var val2 = this._getValue(frmElt.elements[c.confirmFieldOf]); 207 if(val != val2){ 208 f.errorDecorator.addError(c, 2); 209 valid = false; 210 } 211 } 204 212 } 205 213 if(!valid) … … 309 317 this.errRequired = ''; 310 318 this.help=''; 319 this.isConfirmField = false; 320 this.confirmFieldOf = ''; 311 321 } 312 322 trunk/lib/jelix-www/js/jforms.js
r530 r540 13 13 usage : 14 14 15 gForm = new jFormsForm('name'); // create a form descriptor16 gForm.setErrorDecorator(new jFormsErrorDecoratorAlert()); // declare an error handler15 jForms.tForm = new jFormsForm('name'); // create a form descriptor 16 jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorAlert()); // declare an error handler 17 17 18 18 // declare a form control 19 gControl = new jFormsControl('name', 'a label', 'datatype');20 gControl.required = true;21 gControl.errInvalid='';22 gControl.errRequired='';23 gForm.addControl( gControl);19 jForms.tControl = new jFormsControl('name', 'a label', 'datatype'); 20 jForms.tControl.required = true; 21 jForms.tControl.errInvalid=''; 22 jForms.tControl.errRequired=''; 23 jForms.tForm.addControl( gControl); 24 24 ... 25 25 26 26 // declare the form now 27 jForms.declareForm( gForm);27 jForms.declareForm(jForms.tForm); 28 28 29 29 On a form tag : … … 32 32 */ 33 33 34 35 var gForm, gControl;36 37 34 /* 38 35 … … 40 37 var jForms = { 41 38 _forms: {}, 39 40 tForm: null, 41 tControl: null, 42 tControl2: null, 42 43 43 44 declareForm : function(aForm){ … … 202 203 } 203 204 } 205 if(c.isConfirmField){ 206 var val2 = this._getValue(frmElt.elements[c.confirmFieldOf]); 207 if(val != val2){ 208 f.errorDecorator.addError(c, 2); 209 valid = false; 210 } 211 } 204 212 } 205 213 if(!valid) … … 309 317 this.errRequired = ''; 310 318 this.help=''; 319 this.isConfirmField = false; 320 this.confirmFieldOf = ''; 311 321 } 312 322 trunk/lib/jelix/docs/ns/jforms-controls.rng
r528 r540 164 164 <ref name="UI.attr.readonly" /> 165 165 <ref name="UI.attr.required" /> 166 <optional> 167 <element name="confirm"> 168 <empty/> 169 <choice> 170 <attribute name="label" /> 171 <attribute name="labellocale" /> 172 </choice> 173 </element> 174 </optional> 166 175 </element> 167 176 </define> … … 193 202 </define> 194 203 195 <!--196 <define name="select1">197 <element name="select1">198 <ref name="UI.Common" />199 <ref name="List.UI.Common" />200 <optional>201 <attribute name="appearance">202 <choice>203 <value>radiobuttons</value>204 <value>listbox</value>205 <value>menulist</value>206 </choice>207 </attribute>208 </optional>209 </element>210 </define>211 -->212 204 <define name="radiobuttons"> 213 205 <element name="radiobuttons"> … … 242 234 </element> 243 235 </define> 244 245 246 <!-- <define name="select">247 <element name="select">248 <ref name="UI.Common" />249 <ref name="List.UI.Common" />250 <optional>251 <attribute name="appearance">252 <choice>253 <value>checkbox</value>254 <value>listbox</value>255 </choice>256 </attribute>257 </optional>258 </element>259 </define>-->260 236 261 237 <define name="output"> … … 263 239 <ref name="UI.Common" /> 264 240 <ref name="UI.attr.defaultvalue" /> 265 <!--<optional><attribute name="value"/></optional>-->266 241 </element> 267 242 </define> … … 270 245 <element name="submit"> 271 246 <ref name="UI.Common" /> 272 <!--<optional><attribute name="value"/></optional>--> 273 </element> 274 </define> 275 --> 247 </element> 248 </define> 249 276 250 277 251 <!-- trunk/lib/jelix/docs/ns/jforms-controls.rng
r528 r540 164 164 <ref name="UI.attr.readonly" /> 165 165 <ref name="UI.attr.required" /> 166 <optional> 167 <element name="confirm"> 168 <empty/> 169 <choice> 170 <attribute name="label" /> 171 <attribute name="labellocale" /> 172 </choice> 173 </element> 174 </optional> 166 175 </element> 167 176 </define> … … 193 202 </define> 194 203 195 <!--196 <define name="select1">197 <element name="select1">198 <ref name="UI.Common" />199 <ref name="List.UI.Common" />200 <optional>201 <attribute name="appearance">202 <choice>203 <value>radiobuttons</value>204 <value>listbox</value>205 <value>menulist</value>206 </choice>207 </attribute>208 </optional>209 </element>210 </define>211 -->212 204 <define name="radiobuttons"> 213 205 <element name="radiobuttons"> … … 242 234 </element> 243 235 </define> 244 245 246 <!-- <define name="select">247 <element name="select">248 <ref name="UI.Common" />249 <ref name="List.UI.Common" />250 <optional>251 <attribute name="appearance">252 <choice>253 <value>checkbox</value>254 <value>listbox</value>255 </choice>256 </attribute>257 </optional>258 </element>259 </define>-->260 236 261 237 <define name="output"> … … 263 239 <ref name="UI.Common" /> 264 240 <ref name="UI.attr.defaultvalue" /> 265 <!--<optional><attribute name="value"/></optional>-->266 241 </element> 267 242 </define> … … 270 245 <element name="submit"> 271 246 <ref name="UI.Common" /> 272 <!--<optional><attribute name="value"/></optional>--> 273 </element> 274 </define> 275 --> 247 </element> 248 </define> 249 276 250 277 251 <!-- trunk/lib/jelix/forms/jFormsBase.class.php
r530 r540 9 9 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 10 10 */ 11 12 /**13 *14 */15 16 define('JFORM_ERRDATA_INVALID',1);17 define('JFORM_ERRDATA_REQUIRED',2);18 11 19 12 /** … … 101 94 $this->_container->errors = array(); 102 95 foreach($this->_controls as $name=>$ctrl){ 103 $value=$this->_container->datas[$name]; 104 if(is_array($value)){ 105 if(count($value) == 0 && $ctrl->required){ 106 $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 107 }else{ 108 foreach($value as $v){ 109 if(!$ctrl->datatype->check($v)){ 110 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 111 break; 112 } 113 } 114 } 115 }else{ 116 if($value == '' && $ctrl->required){ 117 $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 118 }else{ 119 if($ctrl->type == 'checkbox'){ 120 if($value != $ctrl->valueOnCheck && $value != $ctrl->valueOnUncheck) 121 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 122 }elseif(!$ctrl->datatype->check($value)){ 123 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 124 } 125 } 126 } 96 $err = $ctrl->check($this->_container->datas[$name], $this); 97 if($err !== null) 98 $this->_container->errors[$name]= $err; 127 99 } 128 100 return count($this->_container->errors) == 0; … … 351 323 if($this->_controls[$name]->type == 'checkbox') { 352 324 if($value != $this->_controls[$name]->valueOnCheck){ 353 $value = $this->_controls[$name]->valueOnUncheck; 325 if($value =='on') 326 $value = $this->_controls[$name]->valueOnCheck; 327 else 328 $value = $this->_controls[$name]->valueOnUncheck; 354 329 } 355 330 } trunk/lib/jelix/forms/jFormsBase.class.php
r530 r540 9 9 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 10 10 */ 11 12 /**13 *14 */15 16 define('JFORM_ERRDATA_INVALID',1);17 define('JFORM_ERRDATA_REQUIRED',2);18 11 19 12 /** … … 101 94 $this->_container->errors = array(); 102 95 foreach($this->_controls as $name=>$ctrl){ 103 $value=$this->_container->datas[$name]; 104 if(is_array($value)){ 105 if(count($value) == 0 && $ctrl->required){ 106 $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 107 }else{ 108 foreach($value as $v){ 109 if(!$ctrl->datatype->check($v)){ 110 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 111 break; 112 } 113 } 114 } 115 }else{ 116 if($value == '' && $ctrl->required){ 117 $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 118 }else{ 119 if($ctrl->type == 'checkbox'){ 120 if($value != $ctrl->valueOnCheck && $value != $ctrl->valueOnUncheck) 121 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 122 }elseif(!$ctrl->datatype->check($value)){ 123 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 124 } 125 } 126 } 96 $err = $ctrl->check($this->_container->datas[$name], $this); 97 if($err !== null) 98 $this->_container->errors[$name]= $err; 127 99 } 128 100 return count($this->_container->errors) == 0; … … 351 323 if($this->_controls[$name]->type == 'checkbox') { 352 324 if($value != $this->_controls[$name]->valueOnCheck){ 353 $value = $this->_controls[$name]->valueOnUncheck; 325 if($value =='on') 326 $value = $this->_controls[$name]->valueOnCheck; 327 else 328 $value = $this->_controls[$name]->valueOnUncheck; 354 329 } 355 330 } trunk/lib/jelix/forms/jFormsBuilderBase.class.php
r527 r540 264 264 break; 265 265 case 'secret': 266 case 'secretconfirm': 266 267 echo '<input type="password"',$id,$readonly,$hint,$class,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 267 268 break; trunk/lib/jelix/forms/jFormsBuilderBase.class.php
r527 r540 264 264 break; 265 265 case 'secret': 266 case 'secretconfirm': 266 267 echo '<input type="password"',$id,$readonly,$hint,$class,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 267 268 break; trunk/lib/jelix/forms/jFormsCompiler.class.php
r530 r540 62 62 63 63 $srcjs=array(); 64 $srcjs[]='$js=" gForm = new jFormsForm(\'".$this->_name."\');\n";';65 $srcjs[]='$js.=" gForm.setErrorDecorator(new ".$errorDecoratorName."());\n";';66 $srcjs[]='$js.=" gForm.setHelpDecorator(new ".$helpDecoratorName."());\n";';64 $srcjs[]='$js="jForms.tForm = new jFormsForm(\'".$this->_name."\');\n";'; 65 $srcjs[]='$js.="jForms.tForm.setErrorDecorator(new ".$errorDecoratorName."());\n";'; 66 $srcjs[]='$js.="jForms.tForm.setHelpDecorator(new ".$helpDecoratorName."());\n";'; 67 67 foreach($xml->children() as $controltype=>$control){ 68 68 $source[] = $this->generatePHPControl($controltype, $control); … … 76 76 77 77 jFile::write($cachefile, implode("\n", $source)); 78 $srcjs[]='$js.="jForms.declareForm( gForm);\n";';78 $srcjs[]='$js.="jForms.declareForm(jForms.tForm);\n";'; 79 79 80 80 $srcHtmlBuilder[]=' public function getJavascriptCheck($errorDecoratorName, $helpDecoratorName){'; … … 115 115 throw new jException('jelix~formserr.datatype.unknow',array($dt,$controltype,$this->sourceFile)); 116 116 } 117 $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 117 if($dt != 'string') 118 $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 118 119 }else if($controltype == 'checkbox') { 119 120 $source[]='$ctrl->datatype= new jDatatypeBoolean();'; 120 }else{ 121 $source[]='$ctrl->datatype= new jDatatypeString();'; 122 } 121 } 122 123 123 // readonly support 124 124 if(isset($control['readonly'])){ … … 170 170 } 171 171 } 172 $alertInvalid=''; 173 $alertRequired=''; 172 174 if(isset($control->alert)){ 173 $alertInvalid='';174 $alertRequired='';175 176 175 foreach($control->alert as $alert){ 177 176 if(isset($alert['locale'])){ … … 193 192 if($alertInvalid !='') $source[]=$alertInvalid; 194 193 } 195 196 // support of static datas or daos 194 $hasCtrl2 = false; 197 195 switch($controltype){ 198 196 case 'checkboxes': … … 200 198 case 'menulist': 201 199 case 'listbox': 200 // support of static datas or daos 202 201 if(isset($control['selectedvalue']) && isset($control->selectedvalues)){ 203 202 throw new jException('jelix~formserr.attribute.not.allowed',array('selectedvalue',$controltype,$this->sourceFile)); … … 263 262 264 263 break; 264 case 'secret': 265 if(isset($control->confirm)) { 266 $label=''; 267 if(isset($control->confirm['label'])){ 268 $label = "'".str_replace("'","\\'",(string)$control->confirm['label'])."';"; 269 }elseif(isset($control->confirm['labellocale'])){ 270 $label = "jLocale::get('".(string)$control->confirm['labellocale']."');"; 271 }else{ 272 throw new jException('jelix~formserr.attribute.missing',array('label','confirm',$this->sourceFile)); 273 } 274 $source[]='$ctrl2 = new jFormsControlSecretConfirm(\''.(string)$control['ref'].'_confirm\');'; 275 $source[]='$ctrl2->primarySecret = \''.(string)$control['ref'].'\';'; 276 $source[]='$ctrl2->label='.$label; 277 $source[]='$ctrl2->required = $ctrl->required;'; 278 $source[]='$ctrl2->readonly = $ctrl->readonly;'; 279 if($alertInvalid!='') 280 $source[]='$ctrl2->alertInvalid = $ctrl->alertInvalid;'; 281 if($alertRequired!='') 282 $source[]='$ctrl2->alertRequired = $ctrl->alertRequired;'; 283 284 if(isset($control->help)){ 285 $source[]='$ctrl2->hasHelp=true;'; 286 } 287 if(isset($control->hint)){ 288 $source[]='$ctrl2->hint=$ctrl->hint;'; 289 } 290 $hasCtrl2 = true; 291 } 292 break; 265 293 } 266 294 … … 292 320 293 321 $source[]='$this->addControl($ctrl);'; 322 if($hasCtrl2) 323 $source[]='$this->addControl($ctrl2);'; 294 324 return implode("\n", $source); 295 325 } … … 299 329 return ''; 300 330 331 if(isset($control->confirm) && $controltype == 'secret') { 332 $hasConfirm = true; 333 }else{ 334 $hasConfirm = false; 335 } 336 301 337 $source = array(); 302 338 … … 314 350 } 315 351 if($controltype == 'checkboxes' || ($controltype == 'listbox' && isset($control['multiple']) && 'true' == (string)$control['multiple'])) 316 $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'[]\', \'".$label."\', \''.$dt.'\');\n";'; 317 else 318 $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 352 $source[]='$js.="jForms.tControl = new jFormsControl(\''.(string)$control['ref'].'[]\', \'".$label."\', \''.$dt.'\');\n";'; 353 else{ 354 $source[]='$js.="jForms.tControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 355 if($hasConfirm){ 356 if(isset($control->confirm['label'])){ 357 $source[]='$label2 = str_replace("\'","\\\'",\''.str_replace("'","\\'",(string)$control->confirm['label']).'\');'; 358 }else{ 359 $source[]='$label2 = str_replace("\'","\\\'",jLocale::get(\''.(string)$control->confirm['labellocale'].'\'));'; 360 } 361 $source[]='$js.="jForms.tControl2 = new jFormsControl(\''.(string)$control['ref'].'_confirm\', \'".$label2."\', \''.$dt.'\');\n";'; 362 } 363 } 319 364 320 365 if($dt == 'localedate' || $dt =='localedatetime' || $dt =='localetime'){ 321 $source[]='$js.=" gControl.lang=\'".$GLOBALS[\'gJConfig\']->defaultLocale."\';\n";';366 $source[]='$js.="jForms.tControl.lang=\'".$GLOBALS[\'gJConfig\']->defaultLocale."\';\n";'; 322 367 } 323 368 324 369 if(isset($control['readonly']) && 'true' == (string)$control['readonly']){ 325 $source[]='$js.="gControl.readonly = true;\n";'; 370 $source[]='$js.="jForms.tControl.readonly = true;\n";'; 371 if($hasConfirm) $source[]='$js.="jForms.tControl2.readonly = true;\n";'; 326 372 } 327 373 if(isset($control['required']) && 'true' == (string)$control['required']){ 328 $source[]='$js.="gControl.required = true;\n";'; 374 $source[]='$js.="jForms.tControl.required = true;\n";'; 375 if($hasConfirm) $source[]='$js.="jForms.tControl2.required = true;\n";'; 329 376 } 330 377 … … 335 382 $help='str_replace("\'","\\\'",\''.str_replace("'","\\'",(string)$control->help).'\')'; 336 383 } 337 $source[]='$js.="gControl.help=\'".'.$help.'."\';\n";'; 384 $source[]='$js.="jForms.tControl.help=\'".'.$help.'."\';\n";'; 385 if($hasConfirm) $source[]='$js.="jForms.tControl2.help=jForms.tControl.help;\n";'; 338 386 } 339 387 … … 360 408 } 361 409 362 $source[]='$js.="gControl.errRequired=\'".'.$alertRequired.'."\';\n";'; 363 $source[]='$js.="gControl.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 410 $source[]='$js.="jForms.tControl.errRequired=\'".'.$alertRequired.'."\';\n";'; 411 $source[]='$js.="jForms.tControl.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 412 if($hasConfirm){ 413 $alertInvalid='str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label2))'; 414 $alertRequired='str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label2))'; 415 $source[]='$js.="jForms.tControl2.errRequired=\'".'.$alertRequired.'."\';\n";'; 416 $source[]='$js.="jForms.tControl2.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 417 } 418 364 419 if(isset($control['multiple']) && 'true' == (string)$control['multiple']){ 365 $source[]='$js.="gControl.multiple = true;\n";'; 366 } 367 368 $source[]='$js.="gForm.addControl( gControl);\n";'; 420 $source[]='$js.="jForms.tControl.multiple = true;\n";'; 421 } 422 $source[]='$js.="jForms.tForm.addControl( jForms.tControl);\n";'; 423 if($hasConfirm) { 424 $source[]='$js.="jForms.tControl2.isConfirmField=true;\njForms.tControl2.confirmFieldOf=\''.(string)$control['ref'].'\';\n";'; 425 $source[]='$js.="jForms.tForm.addControl( jForms.tControl2);\n";'; 426 } 369 427 370 428 return implode("\n", $source); … … 377 435 au final, le javascript généré dans la page html doit ressembler à cela 378 436 379 gForm = new jFormsForm('name');380 gForm.setDecorator(new jFormsErrorDecoratorAlert());437 jForms.tForm = new jFormsForm('name'); 438 jForms.tForm.setDecorator(new jFormsErrorDecoratorAlert()); 381 439 382 gControl = new jFormsControl('name', 'a label', 'datatype');383 gControl.required = true;384 gControl.errInvalid='';385 gControl.errRequired='';386 gForm.addControl( gControl);440 jForms.tControl = new jFormsControl('name', 'a label', 'datatype'); 441 jForms.tControl.required = true; 442 jForms.tControl.errInvalid=''; 443 jForms.tControl.errRequired=''; 444 jForms.tForm.addControl( jForms.tControl); 387 445 ... 388 jForms.declareForm( gForm);446 jForms.declareForm(jForms.tForm); 389 447 390 448 … … 394 452 // le code php généré dans le builder 395 453 396 $js=" gForm = new jFormsForm('".$this->getFormName()."');\n";397 $js.=" gForm.setDecorator(new jFormsErrorDecoratorAlert());\n";454 $js="jForms.tForm = new jFormsForm('".$this->getFormName()."');\n"; 455 $js.="jForms.tForm.setDecorator(new jFormsErrorDecoratorAlert());\n"; 398 456 $label = 'a label'; 399 457 ou 400 458 $label = jLocale::get('mod~cle_locale_user'); 401 $js.=" gControl = new jFormsControl('name', '".str_replace("'","\\'", $label)."', 'datatype');\n";402 $js.=" gControl.required = true;\n";459 $js.="jForms.tControl = new jFormsControl('name', '".str_replace("'","\\'", $label)."', 'datatype');\n"; 460 $js.="jForms.tControl.required = true;\n"; 403 461 404 462 $invalid = jLocale::get('jelix~forms.check.invalid',$label)); … … 407 465 ou 408 466 $invalid = 'bla bla'; 409 $js.=" gControl.errInvalid='".str_replace("'","\\'",$invalid)."';\n";467 $js.="jForms.tControl.errInvalid='".str_replace("'","\\'",$invalid)."';\n"; 410 468 411 469 … … 416 474 $required = 'bla bla'; 417 475 418 $js.=" gControl.errRequired='".str_replace("'","\\'",$required)."';\n";419 $js.=" gForm.addControl( gControl);\n";476 $js.="jForms.tControl.errRequired='".str_replace("'","\\'",$required)."';\n"; 477 $js.="jForms.tForm.addControl( jForms.tControl);\n"; 420 478 ... 421 $js.="jForms.declareForm( gForm);\n";479 $js.="jForms.declareForm(jForms.tForm);\n"; 422 480 423 481 */ trunk/lib/jelix/forms/jFormsCompiler.class.php
r530 r540 62 62 63 63 $srcjs=array(); 64 $srcjs[]='$js=" gForm = new jFormsForm(\'".$this->_name."\');\n";';65 $srcjs[]='$js.=" gForm.setErrorDecorator(new ".$errorDecoratorName."());\n";';66 $srcjs[]='$js.=" gForm.setHelpDecorator(new ".$helpDecoratorName."());\n";';64 $srcjs[]='$js="jForms.tForm = new jFormsForm(\'".$this->_name."\');\n";'; 65 $srcjs[]='$js.="jForms.tForm.setErrorDecorator(new ".$errorDecoratorName."());\n";'; 66 $srcjs[]='$js.="jForms.tForm.setHelpDecorator(new ".$helpDecoratorName."());\n";'; 67 67 foreach($xml->children() as $controltype=>$control){ 68 68 $source[] = $this->generatePHPControl($controltype, $control); … … 76 76 77 77 jFile::write($cachefile, implode("\n", $source)); 78 $srcjs[]='$js.="jForms.declareForm( gForm);\n";';78 $srcjs[]='$js.="jForms.declareForm(jForms.tForm);\n";'; 79 79 80 80 $srcHtmlBuilder[]=' public function getJavascriptCheck($errorDecoratorName, $helpDecoratorName){'; … … 115 115 throw new jException('jelix~formserr.datatype.unknow',array($dt,$controltype,$this->sourceFile)); 116 116 } 117 $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 117 if($dt != 'string') 118 $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 118 119 }else if($controltype == 'checkbox') { 119 120 $source[]='$ctrl->datatype= new jDatatypeBoolean();'; 120 }else{ 121 $source[]='$ctrl->datatype= new jDatatypeString();'; 122 } 121 } 122 123 123 // readonly support 124 124 if(isset($control['readonly'])){ … … 170 170 } 171 171 } 172 $alertInvalid=''; 173 $alertRequired=''; 172 174 if(isset($control->alert)){ 173 $alertInvalid='';174 $alertRequired='';175 176 175 foreach($control->alert as $alert){ 177 176 if(isset($alert['locale'])){ … … 193 192 if($alertInvalid !='') $source[]=$alertInvalid; 194 193 } 195 196 // support of static datas or daos 194 $hasCtrl2 = false; 197 195 switch($controltype){ 198 196 case 'checkboxes': … … 200 198 case 'menulist': 201 199 case 'listbox': 200 // support of static datas or daos 202 201 if(isset($control['selectedvalue']) && isset($control->selectedvalues)){ 203 202 throw new jException('jelix~formserr.attribute.not.allowed',array('selectedvalue',$controltype,$this->sourceFile)); … … 263 262 264 263 break; 264 case 'secret': 265 if(isset($control->confirm)) { 266 $label=''; 267 if(isset($control->confirm['label'])){ 268 $label = "'".str_replace("'","\\'",(string)$control->confirm['label'])."';"; 269 }elseif(isset($control->confirm['labellocale'])){ 270 $label = "jLocale::get('".(string)$control->confirm['labellocale']."');"; 271 }else{ 272 throw new jException('jelix~formserr.attribute.missing',array('label','confirm',$this->sourceFile)); 273 } 274 $source[]='$ctrl2 = new jFormsControlSecretConfirm(\''.(string)$control['ref'].'_confirm\');'; 275 $source[]='$ctrl2->primarySecret = \''.(string)$control['ref'].'\';'; 276 $source[]='$ctrl2->label='.$label; 277 $source[]='$ctrl2->required = $ctrl->required;'; 278 $source[]='$ctrl2->readonly = $ctrl->readonly;'; 279 if($alertInvalid!='') 280 $source[]='$ctrl2->alertInvalid = $ctrl->alertInvalid;'; 281 if($alertRequired!='') 282 $source[]='$ctrl2->alertRequired = $ctrl->alertRequired;'; 283 284 if(isset($control->help)){ 285 $source[]='$ctrl2->hasHelp=true;'; 286 } 287 if(isset($control->hint)){ 288 $source[]='$ctrl2->hint=$ctrl->hint;'; 289 } 290 $hasCtrl2 = true; 291 } 292 break; 265 293 } 266 294 … … 292 320 293 321 $source[]='$this->addControl($ctrl);'; 322 if($hasCtrl2) 323 $source[]='$this->addControl($ctrl2);'; 294 324 return implode("\n", $source); 295 325 } … … 299 329 return ''; 300 330 331 if(isset($control->confirm) && $controltype == 'secret') { 332 $hasConfirm = true; 333 }else{ 334 $hasConfirm = false; 335 } 336 301 337 $source = array(); 302 338 … … 314 350 } 315 351 if($controltype == 'checkboxes' || ($controltype == 'listbox' && isset($control['multiple']) && 'true' == (string)$control['multiple'])) 316 $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'[]\', \'".$label."\', \''.$dt.'\');\n";'; 317 else 318 $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 352 $source[]='$js.="jForms.tControl = new jFormsControl(\''.(string)$control['ref'].'[]\', \'".$label."\', \''.$dt.'\');\n";'; 353 else{ 354 $source[]='$js.="jForms.tControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 355 if($hasConfirm){ 356 if(isset($control->confirm['label'])){ 357 $source[]='$label2 = str_replace("\'","\\\'",\''.str_replace("'","\\'",(string)$control->confirm['label']).'\');'; 358 }else{ 359 $source[]='$label2 = str_replace("\'","\\\'",jLocale::get(\''.(string)$control->confirm['labellocale'].'\'));'; 360 } 361 $source[]='$js.="jForms.tControl2 = new jFormsControl(\''.(string)$control['ref'].'_confirm\', \'".$label2."\', \''.$dt.'\');\n";'; 362 } 363 } 319 364 320 365 if($dt == 'localedate' || $dt =='localedatetime' || $dt =='localetime'){ 321 $source[]='$js.=" gControl.lang=\'".$GLOBALS[\'gJConfig\']->defaultLocale."\';\n";';366 $source[]='$js.="jForms.tControl.lang=\'".$GLOBALS[\'gJConfig\']->defaultLocale."\';\n";'; 322 367 } 323 368 324 369 if(isset($control['readonly']) && 'true' == (string)$control['readonly']){ 325 $source[]='$js.="gControl.readonly = true;\n";'; 370 $source[]='$js.="jForms.tControl.readonly = true;\n";'; 371 if($hasConfirm) $source[]='$js.="jForms.tControl2.readonly = true;\n";'; 326 372 } 327 373 if(isset($control['required']) && 'true' == (string)$control['required']){ 328 $source[]='$js.="gControl.required = true;\n";'; 374 $source[]='$js.="jForms.tControl.required = true;\n";'; 375 if($hasConfirm) $source[]='$js.="jForms.tControl2.required = true;\n";'; 329 376 } 330 377 … … 335 382 $help='str_replace("\'","\\\'",\''.str_replace("'","\\'",(string)$control->help).'\')'; 336 383 } 337 $source[]='$js.="gControl.help=\'".'.$help.'."\';\n";'; 384 $source[]='$js.="jForms.tControl.help=\'".'.$help.'."\';\n";'; 385 if($hasConfirm) $source[]='$js.="jForms.tControl2.help=jForms.tControl.help;\n";'; 338 386 } 339 387 … … 360 408 } 361 409 362 $source[]='$js.="gControl.errRequired=\'".'.$alertRequired.'."\';\n";'; 363 $source[]='$js.="gControl.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 410 $source[]='$js.="jForms.tControl.errRequired=\'".'.$alertRequired.'."\';\n";'; 411 $source[]='$js.="jForms.tControl.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 412 if($hasConfirm){ 413 $alertInvalid='str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label2))'; 414 $alertRequired='str_replace("\'","\\\'",jLocale::get(\
