Changeset 1069 for trunk/lib
- Timestamp:
- 08/27/08 23:57:27 (3 months ago)
- Files:
-
- trunk/lib/jelix-www/js/jforms.js (modified) (4 diffs)
- trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/jelix-www/js/jforms.js
r1054 r1069 17 17 18 18 // declare a form control 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);19 var c = new jFormsControl('name', 'a label', 'datatype'); 20 c.required = true; 21 c.errInvalid=''; 22 c.errRequired=''; 23 jForms.tForm.addControl(c); 24 24 ... 25 25 26 // declare the form now 26 // declare the form now. A 'submit" event handler will be attached to the corresponding form element 27 27 jForms.declareForm(jForms.tForm); 28 29 //On a form tag, you should add this onsubmit attribute :30 onsubmit="return jForms.verifyForm(this)"31 28 32 29 */ … … 39 36 40 37 tForm: null, 41 tControl: null,42 tControl2: null,43 38 frmElt: null, 44 39 … … 611 606 612 607 var list = this.items[val]; 608 var valid = true; 613 609 for(var i=0; i < list.length; i++) { 614 610 var val2 = jfrm.getValue(jfrm.frmElt.elements[list[i].name]); … … 617 613 if (list[i].required) { 618 614 jfrm.tForm.errorDecorator.addError(list[i], 1); 615 valid = false; 619 616 } 620 617 } else if (!list[i].check(val2, jfrm)) { 621 618 jfrm.tForm.errorDecorator.addError(list[i], 2); 622 } 623 } 624 return true; 619 valid = false; 620 } 621 } 622 return valid; 625 623 }, 626 624 activate : function (val) { trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php
r1067 r1069 158 158 echo '<script type="text/javascript"> 159 159 //<![CDATA[ 160 (function(){var c, c2; 160 161 '.$this->jsContent.' 162 })(); 161 163 //]]> 162 164 </script>'; … … 192 194 } 193 195 196 protected function escJsStr($str) { 197 return '\''.str_replace(array("'","\n"),array("\\'", "\\n"), $str).'\''; 198 } 199 194 200 protected function commonJs($ctrl) { 195 201 if($ctrl->help){ 196 $this->jsContent .=" jForms.tControl.help='".str_replace("'","\\'",$ctrl->help)."';\n";202 $this->jsContent .="c.help=".$this->escJsStr($ctrl->help).";\n"; 197 203 } 198 204 199 205 if($ctrl->required){ 200 $this->jsContent .=" jForms.tControl.required = true;\n";206 $this->jsContent .="c.required = true;\n"; 201 207 if($ctrl->alertRequired){ 202 $this->jsContent .=" jForms.tControl.errRequired='".str_replace("'","\\'",$ctrl->alertRequired)."';\n";208 $this->jsContent .="c.errRequired=".$this->escJsStr($ctrl->alertRequired).";\n"; 203 209 } 204 210 else { 205 $this->jsContent .=" jForms.tControl.errRequired='".str_replace("'","\\'",jLocale::get('jelix~formserr.js.err.required', $ctrl->label))."';\n";211 $this->jsContent .="c.errRequired=".$this->escJsStr(jLocale::get('jelix~formserr.js.err.required', $ctrl->label)).";\n"; 206 212 } 207 213 } 208 214 209 215 if($ctrl->alertInvalid){ 210 $this->jsContent .=" jForms.tControl.errInvalid='".str_replace("'","\\'",$ctrl->alertInvalid)."';\n";216 $this->jsContent .="c.errInvalid=".$this->escJsStr($ctrl->alertInvalid).";\n"; 211 217 } 212 218 else { 213 $this->jsContent .=" jForms.tControl.errInvalid='".str_replace("'","\\'",jLocale::get('jelix~formserr.js.err.invalid', $ctrl->label))."';\n";214 } 215 216 if ($this->isRootControl) $this->jsContent .="jForms.tForm.addControl( jForms.tControl);\n";219 $this->jsContent .="c.errInvalid=".$this->escJsStr(jLocale::get('jelix~formserr.js.err.invalid', $ctrl->label)).";\n"; 220 } 221 222 if ($this->isRootControl) $this->jsContent .="jForms.tForm.addControl(c);\n"; 217 223 } 218 224 … … 245 251 $dt = 'String'; 246 252 247 $this->jsContent .=" jForms.tControl = new jFormsControl".$dt."('".$ctrl->ref."', '".str_replace("'","\'",$ctrl->label)."');\n";253 $this->jsContent .="c = new jFormsControl".$dt."('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n"; 248 254 if ($isLocale) 249 $this->jsContent .=" jForms.tControl.lang='".$GLOBALS['gJConfig']->locale."';\n";255 $this->jsContent .="c.lang='".$GLOBALS['gJConfig']->locale."';\n"; 250 256 251 257 $maxl= $ctrl->datatype->getFacet('maxLength'); 252 258 if($maxl !== null) 253 $this->jsContent .=" jForms.tControl.maxLength = '$maxl';\n";259 $this->jsContent .="c.maxLength = '$maxl';\n"; 254 260 255 261 $minl= $ctrl->datatype->getFacet('minLength'); 256 262 if($minl !== null) 257 $this->jsContent .=" jForms.tControl.minLength = '$minl';\n";263 $this->jsContent .="c.minLength = '$minl';\n"; 258 264 259 265 $this->commonJs($ctrl); … … 273 279 protected function jsCheckbox($ctrl) { 274 280 275 $this->jsContent .=" jForms.tControl = new jFormsControlBoolean('".$ctrl->ref."', '".str_replace("'","\'",$ctrl->label)."');\n";281 $this->jsContent .="c = new jFormsControlBoolean('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n"; 276 282 277 283 $this->commonJs($ctrl); … … 309 315 protected function jsCheckboxes($ctrl) { 310 316 311 $this->jsContent .=" jForms.tControl = new jFormsControlString('".$ctrl->ref."[]', '".str_replace("'","\'",$ctrl->label)."');\n";317 $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."[]', ".$this->escJsStr($ctrl->label).");\n"; 312 318 313 319 $this->commonJs($ctrl); … … 334 340 protected function jsRadiobuttons($ctrl) { 335 341 336 $this->jsContent .=" jForms.tControl = new jFormsControlString('".$ctrl->ref."', '".str_replace("'","\'",$ctrl->label)."');\n";342 $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n"; 337 343 338 344 $this->commonJs($ctrl); … … 359 365 protected function jsMenulist($ctrl) { 360 366 361 $this->jsContent .=" jForms.tControl = new jFormsControlString('".$ctrl->ref."', '".str_replace("'","\'",$ctrl->label)."');\n";367 $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n"; 362 368 363 369 $this->commonJs($ctrl); … … 402 408 protected function jsListbox($ctrl) { 403 409 if($ctrl->multiple){ 404 $this->jsContent .= " jForms.tControl = new jFormsControlString('".$ctrl->ref."[]', '".str_replace("'","\'",$ctrl->label)."');\n";405 $this->jsContent .= " jForms.tControl.multiple = true;\n";410 $this->jsContent .= "c = new jFormsControlString('".$ctrl->ref."[]', ".$this->escJsStr($ctrl->label).");\n"; 411 $this->jsContent .= "c.multiple = true;\n"; 406 412 } else { 407 $this->jsContent .=" jForms.tControl = new jFormsControlString('".$ctrl->ref."', '".str_replace("'","\'",$ctrl->label)."');\n";413 $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n"; 408 414 } 409 415 … … 418 424 419 425 protected function jsTextarea($ctrl) { 420 $this->jsContent .=" jForms.tControl = new jFormsControlString('".$ctrl->ref."', '".str_replace("'","\'",$ctrl->label)."');\n";426 $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n"; 421 427 422 428 $maxl= $ctrl->datatype->getFacet('maxLength'); 423 429 if($maxl !== null) 424 $this->jsContent .=" jForms.tControl.maxLength = '$maxl';\n";430 $this->jsContent .="c.maxLength = '$maxl';\n"; 425 431 426 432 $minl= $ctrl->datatype->getFacet('minLength'); 427 433 if($minl !== null) 428 $this->jsContent .=" jForms.tControl.minLength = '$minl';\n";434 $this->jsContent .="c.minLength = '$minl';\n"; 429 435 430 436 $this->commonJs($ctrl); … … 464 470 protected function jsSecretconfirm($ctrl) { 465 471 // we assume that a secret confirm control is just after a secret control in the list of controls 466 $this->jsContent .= " jForms.tControl.confirmField = new jFormsControlSecretConfirm('".$ctrl->ref."_confirm', '".str_replace("'","\\'",$ctrl->label)."');\n";472 $this->jsContent .= "c.confirmField = new jFormsControlSecretConfirm('".$ctrl->ref."_confirm', ".$this->escJsStr($ctrl->label).");\n"; 467 473 } 468 474 … … 485 491 486 492 protected function jsUpload($ctrl) { 487 $this->jsContent .=" jForms.tControl = new jFormsControlString('".$ctrl->ref."', '".str_replace("'","\'",$ctrl->label)."');\n";493 $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n"; 488 494 489 495 $this->commonJs($ctrl); … … 557 563 $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 558 564 $this->jsChoiceInternal($ctrl); 559 $this->jsContent .=" jForms.tControl2 = jForms.tControl;\n";565 $this->jsContent .="c2 = c;\n"; 560 566 $this->isRootControl = false; 561 567 foreach( $ctrl->items as $itemName=>$listctrl){ … … 579 585 if($ro) $c->setReadOnly(true); 580 586 echo "</span>\n"; 581 $this->jsContent .=" jForms.tControl2.addControl(jForms.tControl, '".str_replace("'","\\'",$itemName)."');\n";587 $this->jsContent .="c2.addControl(c, ".$this->escJsStr($itemName).");\n"; 582 588 } 583 589 if(!$displayedControls) { 584 $this->jsContent .=" jForms.tControl2.items['".str_replace("'","\\'",$itemName)."']=[];\n";590 $this->jsContent .="c2.items[".$this->escJsStr($itemName)."]=[];\n"; 585 591 } 586 592 … … 600 606 $value=''; 601 607 } 602 $this->jsContent .= " jForms.tControl2.activate('".$value."');\n";608 $this->jsContent .= "c2.activate('".$value."');\n"; 603 609 } 604 610 605 611 protected function jsChoiceInternal($ctrl) { 606 612 607 $this->jsContent .=" jForms.tControl = new jFormsControlChoice('".$ctrl->ref."', '".str_replace("'","\'",$ctrl->label)."');\n";613 $this->jsContent .="c = new jFormsControlChoice('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n"; 608 614 609 615 $this->commonJs($ctrl);
