Changeset 1028
- Timestamp:
- 07/19/08 15:53:48 (1 month ago)
- Files:
-
- branches/experimental/jforms-groups/lib/jelix-www/design/jform.css (modified) (1 diff)
- branches/experimental/jforms-groups/lib/jelix-www/js/jforms.js (modified) (4 diffs)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php (modified) (1 diff)
- branches/experimental/jforms-groups/lib/jelix/plugins/jforms/html/html.jformsbuilder.php (modified) (4 diffs)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html_cli.php (modified) (21 diffs)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.htmlbuilder2.html_cli.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/experimental/jforms-groups/lib/jelix-www/design/jform.css
r906 r1028 7 7 .jforms-label {} 8 8 .jforms-value {} 9 .jforms-readonly { color:#aaa; } 9 10 10 11 span.jforms-required, label.jforms-required { font-weight:bold; } branches/experimental/jforms-groups/lib/jelix-www/js/jforms.js
r994 r1028 150 150 frm.helpDecorator.show(ctrl.help); 151 151 } 152 }, 153 154 hasClass: function (elt,clss) { 155 return elt.className.match(new RegExp('(\\s|^)'+clss+'(\\s|$)')); 156 }, 157 addClass: function (elt,clss) { 158 if (!this.hasClass(elt,clss)) elt.className += " "+clss; 159 }, 160 removeClass: function (elt,clss) { 161 if (this.hasClass(elt,clss)) { 162 elt.className = elt.className.replace(new RegExp('(\\s|^)'+clss+'(\\s|$)'),' '); 163 } 152 164 } 153 165 }; … … 166 178 addControl : function(ctrl){ 167 179 this.controls.push(ctrl); 180 ctrl.formName = this.name; 168 181 }, 169 182 … … 174 187 setHelpDecorator : function (decorator){ 175 188 this.helpDecorator = decorator; 189 }, 190 getControl : function(aControlName) { 191 var ctrls = this.controls; 192 for(var i=0; i < ctrls.length; i++){ 193 if (ctrls[i].name == aControlName) { 194 return ctrls[i]; 195 } 196 } 197 return null; 176 198 } 177 199 }; … … 535 557 this.items = {}; 536 558 }; 537 jFormsControlChoice.prototype.addControl = function (ctrl, itemValue) { 538 if(this.items[itemValue] == undefined) 539 this.items[itemValue] = []; 540 this.items[itemValue].push(ctrl); 541 }; 542 jFormsControlChoice.prototype.check = function (val, jfrm) { 543 if(this.items[val] == undefined) 544 return false; 545 546 var list = this.items[val]; 547 for(var i=0; i < list.length; i++) { 548 var val2 = jfrm.getValue(jfrm.frmElt.elements[list[i].name]); 549 550 if (val2 == '') { 551 if (list[i].required) { 552 jfrm.tForm.errorDecorator.addError(list[i], 1); 553 } 554 } else if (!list[i].check(val2, jfrm)) { 555 jfrm.tForm.errorDecorator.addError(list[i], 2); 556 } 557 } 558 return true; 559 }; 559 jFormsControlChoice.prototype = { 560 addControl : function (ctrl, itemValue) { 561 if(this.items[itemValue] == undefined) 562 this.items[itemValue] = []; 563 this.items[itemValue].push(ctrl); 564 }, 565 check : function (val, jfrm) { 566 if(this.items[val] == undefined) 567 return false; 568 569 var list = this.items[val]; 570 for(var i=0; i < list.length; i++) { 571 var val2 = jfrm.getValue(jfrm.frmElt.elements[list[i].name]); 572 573 if (val2 == '') { 574 if (list[i].required) { 575 jfrm.tForm.errorDecorator.addError(list[i], 1); 576 } 577 } else if (!list[i].check(val2, jfrm)) { 578 jfrm.tForm.errorDecorator.addError(list[i], 2); 579 } 580 } 581 return true; 582 }, 583 activate : function (val) { 584 var frmElt = document.getElementById(this.formName); 585 for(var j in this.items) { 586 var list = this.items[j]; 587 for(var i=0; i < list.length; i++) { 588 var elt = frmElt.elements[list[i].name]; 589 if (val == j) { 590 elt.removeAttribute("readonly"); 591 jForms.removeClass(elt, "jforms-readonly"); 592 } else { 593 elt.setAttribute("readonly", "readonly"); 594 jForms.addClass(elt, "jforms-readonly"); 595 } 596 } 597 } 598 } 599 } 560 600 561 601 branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php
r1022 r1028 628 628 } 629 629 630 631 630 function setData($value) { 632 631 parent::setData($value); branches/experimental/jforms-groups/lib/jelix/plugins/jforms/html/html.jformsbuilder.php
r994 r1028 161 161 $class = ($ctrl->required == false || $ro?'':' jforms-required'); 162 162 $class.= (isset($this->_form->getContainer()->errors[$ctrl->ref]) ?' jforms-error':''); 163 $class.= ($ro && $ctrl->type != 'captcha'?' jforms-readonly':''); 164 $readonly = ($ro?' readonly="readonly"':''); 163 165 if($class !='') $class = ' class="'.$class.'"'; 164 $readonly = ($ro?' readonly="readonly"':'');165 166 $hint = ($ctrl->hint == ''?'':' title="'.htmlspecialchars($ctrl->hint).'"'); 166 167 167 $this->{'output'.$ctrl->type}($ctrl, $id, $class, $readonly, $hint); 168 169 168 $this->outputHelp($ctrl); 170 169 } … … 388 387 foreach( $ctrl->items as $itemName=>$listctrl){ 389 388 echo '<li><label><input type="radio"',$id,$i,'" value="',htmlspecialchars($itemName),'"'; 390 echo ($itemName==$value?' checked="checked"':''),$readonly,$this->_endt; 389 echo ($itemName==$value?' checked="checked"':''),$readonly; 390 echo ' onclick="jForms.getForm(\'',$this->_name,'\').getControl(\'',$ctrl->ref,'\').activate(\'',$itemName,'\')"', $this->_endt; 391 391 echo htmlspecialchars($ctrl->itemsNames[$itemName]),'</label> '; 392 392 … … 394 394 if(!$this->_form->isActivated($ref)) continue; 395 395 echo ' <span class="jforms-item-controls">'; 396 // we remove readonly status so when a user change the choice and 397 // javascript is deactivated, it can still change the value of the control 398 $ro = $c->isReadOnly() && $readonly != ''; 399 if($ro) $c->setReadOnly(false); 396 400 $this->outputControlLabel($c); 397 401 echo ' '; 398 402 $this->outputControl($c); 403 if($ro) $c->setReadOnly($ro); 399 404 echo "</span>\n"; 400 405 } … … 403 408 } 404 409 echo "</ul>\n"; 410 411 echo '<script type="text/javascript"> 412 //<![CDATA[ 413 jForms.getForm("',$this->_name,'").getControl("',$ctrl->ref,'").activate("',$value,'"); 414 //]]> 415 </script>'; 405 416 } 406 417 branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html_cli.php
r966 r1028 105 105 $ctrl->required=false; 106 106 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 107 $this->assertEqualOrDiff('<input type="text" name="input1" id="'.$this->formname.'_input1" readonly="readonly" value="laurent"/>', $out);107 $this->assertEqualOrDiff('<input type="text" name="input1" id="'.$this->formname.'_input1" readonly="readonly" class=" jforms-readonly" value="laurent"/>', $out); 108 108 109 109 $ctrl->setReadOnly(false); … … 164 164 $ctrl->setReadOnly(true); 165 165 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 166 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" value="1"/>', $out);166 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" class=" jforms-readonly" value="1"/>', $out); 167 167 168 168 $this->form->setData('chk2', '1'); 169 169 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 170 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" c hecked="checked" value="1"/>', $out);170 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" class=" jforms-readonly" checked="checked" value="1"/>', $out); 171 171 172 172 $ctrl->hint='ceci est un tooltip'; … … 175 175 176 176 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 177 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" title="ceci est un tooltip" c hecked="checked" value="1"/>', $out);177 $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" checked="checked" value="1"/>', $out); 178 178 } 179 179 … … 249 249 250 250 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 251 $result='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_0" value="10" checked="checked" readonly="readonly" /><label for="'.$this->formname.'_choixmultiple_0">foo</label></span>';252 $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_1" value="11" readonly="readonly" /><label for="'.$this->formname.'_choixmultiple_1">bar</label></span>';253 $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_2" value="23" checked="checked" readonly="readonly" /><label for="'.$this->formname.'_choixmultiple_2">baz</label></span>';251 $result='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_0" value="10" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_choixmultiple_0">foo</label></span>'; 252 $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_1" value="11" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_choixmultiple_1">bar</label></span>'; 253 $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_2" value="23" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_choixmultiple_2">baz</label></span>'; 254 254 $this->assertEqualOrDiff($result, $out); 255 255 … … 306 306 307 307 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 308 $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_0" value="10" readonly="readonly" /><label for="'.$this->formname.'_rbchoixsimple_0">foo</label></span>';309 $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_1" value="11" readonly="readonly" /><label for="'.$this->formname.'_rbchoixsimple_1">bar</label></span>';310 $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_2" value="23" checked="checked" readonly="readonly" /><label for="'.$this->formname.'_rbchoixsimple_2">baz</label></span>';308 $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_0" value="10" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_rbchoixsimple_0">foo</label></span>'; 309 $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_1" value="11" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_rbchoixsimple_1">bar</label></span>'; 310 $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_2" value="23" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_rbchoixsimple_2">baz</label></span>'; 311 311 $this->assertEqualOrDiff($result, $out); 312 312 } … … 358 358 359 359 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 360 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" size="1">';360 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">'; 361 361 $result.='<option value=""></option>'; 362 362 $result.='<option value="10">foo</option>'; … … 369 369 $this->form->setData('menulist1',"23"); 370 370 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 371 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" size="1">';371 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">'; 372 372 $result.='<option value="10">foo</option>'; 373 373 $result.='<option value="11">bar</option>'; … … 379 379 $this->form->setData('menulist1',""); 380 380 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 381 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" size="1">';381 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">'; 382 382 $result.='<option value="" selected="selected"></option>'; 383 383 $result.='<option value="10">foo</option>'; … … 491 491 492 492 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 493 $result='<select name="listbox1" id="'.$this->formname.'_listbox1" size="4">';493 $result='<select name="listbox1" id="'.$this->formname.'_listbox1" class=" jforms-readonly" size="4">'; 494 494 $result.='<option value="10">foo</option>'; 495 495 $result.='<option value="11">bar</option>'; … … 604 604 $ctrl->setReadOnly(true); 605 605 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 606 $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" rows="5" cols="40">laurent</textarea>', $out);606 $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" class=" jforms-readonly" rows="5" cols="40">laurent</textarea>', $out); 607 607 608 608 $ctrl->hint='ceci est un tooltip'; … … 611 611 612 612 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 613 $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" rows="5" cols="40">laurent</textarea>', $out);613 $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="5" cols="40">laurent</textarea>', $out); 614 614 615 615 $ctrl->rows=20; 616 616 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 617 $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" rows="20" cols="40">laurent</textarea>', $out);617 $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="20" cols="40">laurent</textarea>', $out); 618 618 619 619 $ctrl->cols=60; 620 620 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 621 $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" rows="20" cols="60">laurent</textarea>', $out);621 $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="20" cols="60">laurent</textarea>', $out); 622 622 623 623 } … … 640 640 $ctrl->setReadOnly(true); 641 641 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 642 $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" value="laurent"/>', $out);642 $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" class=" jforms-readonly" value="laurent"/>', $out); 643 643 644 644 $ctrl->hint='ceci est un tooltip'; … … 646 646 $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_passwd" title="ceci est un tooltip">mot de passe</label>', $out); 647 647 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 648 $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" value="laurent"/>', $out);648 $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" value="laurent"/>', $out); 649 649 } 650 650 function testOutputSecretConfirm(){ … … 661 661 $ctrl->setReadOnly(true); 662 662 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 663 $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" value=""/>', $out);663 $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" class=" jforms-readonly" value=""/>', $out); 664 664 665 665 $ctrl->hint='ceci est un tooltip'; … … 667 667 $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_passwd_confirm" title="ceci est un tooltip">confirmation mot de passe</label>', $out); 668 668 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 669 $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" title="ceci est un tooltip" value=""/>', $out);669 $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" value=""/>', $out); 670 670 } 671 671 … … 712 712 $ctrl->setReadOnly(true); 713 713 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 714 $this->assertEqualOrDiff('<input type="file" name="upload1" id="'.$this->formname.'_upload1" readonly="readonly" value=""/>', $out);714 $this->assertEqualOrDiff('<input type="file" name="upload1" id="'.$this->formname.'_upload1" readonly="readonly" class=" jforms-readonly" value=""/>', $out); 715 715 716 716 $ctrl->hint='ceci est un tooltip'; … … 719 719 720 720 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 721 $this->assertEqualOrDiff('<input type="file" name="upload1" id="'.$this->formname.'_upload1" readonly="readonly" title="ceci est un tooltip" value=""/>', $out);721 $this->assertEqualOrDiff('<input type="file" name="upload1" id="'.$this->formname.'_upload1" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" value=""/>', $out); 722 722 723 723 … … 888 888 jelix_wymeditor_default("'.$this->formname.'_contenu","'.$this->formname.'"); 889 889 //]]> 890 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" rows="5" cols="40"><p>Ceci est un contenu</p></textarea>', $out);890 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" class=" jforms-readonly" rows="5" cols="40"><p>Ceci est un contenu</p></textarea>', $out); 891 891 892 892 $ctrl->hint='ceci est un tooltip'; … … 899 899 jelix_wymeditor_default("'.$this->formname.'_contenu","'.$this->formname.'"); 900 900 //]]> 901 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" rows="5" cols="40"><p>Ceci est un contenu</p></textarea>', $out);901 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="5" cols="40"><p>Ceci est un contenu</p></textarea>', $out); 902 902 903 903 $ctrl->rows=20; … … 907 907 jelix_wymeditor_default("'.$this->formname.'_contenu","'.$this->formname.'"); 908 908 //]]> 909 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" rows="20" cols="40"><p>Ceci est un contenu</p></textarea>', $out);909 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="20" cols="40"><p>Ceci est un contenu</p></textarea>', $out); 910 910 911 911 $ctrl->cols=60; … … 915 915 jelix_wymeditor_default("'.$this->formname.'_contenu","'.$this->formname.'"); 916 916 //]]> 917 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" rows="20" cols="60"><p>Ceci est un contenu</p></textarea>', $out);917 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="20" cols="60"><p>Ceci est un contenu</p></textarea>', $out); 918 918 919 919 } branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.htmlbuilder2.html_cli.php
r967 r1028 99 99 $expected .= '<table class="jforms-table-group" border="0">'."\n"; 100 100 $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_nom">Your name</label></th>'."\n"; 101 $expected .= '<td><input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" value=""/></td></tr>'."\n";101 $expected .= '<td><input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></td></tr>'."\n"; 102 102 $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_prenom">Your firstname</label></th>'."\n"; 103 $expected .= '<td><input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" value="robert"/></td></tr>'."\n";103 $expected .= '<td><input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></td></tr>'."\n"; 104 104 $expected .= '<tr><th scope="row"><span class="jforms-label">Vous ĂȘtes </span></th>'."\n"; 105 $expected .= '<td><span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_0" value="h" readonly="readonly" /><label for="'.$this->formname.'_sexe_0">un homme</label></span>';106 $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_1" value="f" readonly="readonly" /><label for="'.$this->formname.'_sexe_1">une femme</label></span>';107 $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_2" value="no" readonly="readonly" /><label for="'.$this->formname.'_sexe_2">je ne sais pas</label></span></td></tr>'."\n";105 $expected .= '<td><span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_0" value="h" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_sexe_0">un homme</label></span>'; 106 $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_1" value="f" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_sexe_1">une femme</label></span>'; 107 $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_2" value="no" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_sexe_2">je ne sais pas</label></span></td></tr>'."\n"; 108 108 $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_mail">Votre mail</label></th>'."\n"; 109 $expected .= '<td><input type="text" name="mail" id="'.$this->formname.'_mail" readonly="readonly" value=""/></td></tr>'."\n</table></fieldset>";109 $expected .= '<td><input type="text" name="mail" id="'.$this->formname.'_mail" readonly="readonly" class=" jforms-readonly" value=""/></td></tr>'."\n</table></fieldset>"; 110 110 ob_start();$this->builder->outputControl($group);$out = ob_get_clean(); 111 111 $this->assertEqualOrDiff($expected, $out); 112 112 113 113 } 114 115 116 function testOutputChoice(){ 117 118 $choice= new jFormsControlChoice('status'); 119 $choice->label='Task Status'; 120 $choice->createItem('new','New'); 121 $choice->createItem('assigned','Assigned'); 122 $choice->createItem('closed','Closed'); 123 124 $ctrl= new jFormsControlinput('nom'); 125 $ctrl->required=true; 126 $ctrl->label='Name'; 127 $choice->addChildControl($ctrl,'assigned'); 128 129 130 $ctrl= new jFormsControlinput('prenom'); 131 $ctrl->defaultValue='robert'; 132 $ctrl->label='Firstname'; 133 $choice->addChildControl($ctrl,'assigned'); 134 135 $ctrl= new jFormsControlMenulist('reason'); 136 $ctrl->required=true; 137 $ctrl->label='Reason '; 138 $ctrl->alertRequired='Hey, specify a reason !'; 139 $ctrl->datasource= new jFormsStaticDatasource(); 140 $ctrl->datasource->data = array( 141 'aa'=>'fixed', 142 'bb'=>'won t fixed', 143 'cc'=>'later', 144 ); 145 $choice->addChildControl($ctrl,'closed'); 146 147 $this->form->addControl($choice); 148 149 150 ob_start();$this->builder->outputControlLabel($choice);$out = ob_get_clean(); 151 $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_status">Task Status</label>', $out); 152 153 154 $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n"; 155 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n"; 156 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label> <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom">Name</label> <input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n"; 157 $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n"; 158 $expected .= '</li>'."\n"; 159 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label> <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason">Reason </label> <select name="reason" id="'.$this->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n"; 160 $expected .= '</li>'."\n"; 161 $expected .= '</ul>'."\n"; 162 $expected .= '<script type="text/javascript">'."\n"; 163 $expected .= '//<![CDATA['."\n"; 164 $expected .= 'jForms.getForm("").getControl("status").activate("");'."\n"; 165 $expected .= '//]]>'."\n"; 166 $expected .= '</script>'; 167 ob_start();$this->builder->outputControl($choice);$out = ob_get_clean(); 168 $this->assertEqualOrDiff($expected, $out); 169 170 $this->form->getContainer()->data['status']='assigned'; 171 172 $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n"; 173 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n"; 174 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_1" value="assigned" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label> <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom">Name</label> <input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n"; 175 $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n"; 176 $expected .= '</li>'."\n"; 177 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label> <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason">Reason </label> <select name="reason" id="'.$this->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n"; 178 $expected .= '</li>'."\n"; 179 $expected .= '</ul>'."\n"; 180 $expected .= '<script type="text/javascript">'."\n"; 181 $expected .= '//<![CDATA['."\n"; 182 $expected .= 'jForms.getForm("").getControl("status").activate("assigned");'."\n"; 183 $expected .= '//]]>'."\n"; 184 $expected .= '</script>'; 185 ob_start();$this->builder->outputControl($choice);$out = ob_get_clean(); 186 $this->assertEqualOrDiff($expected, $out); 187 188 $this->form->getContainer()->data['status']='new'; 189 $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n"; 190 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_0" value="new" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n"; 191 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label> <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom">Name</label> <input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n"; 192 $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n"; 193 $expected .= '</li>'."\n"; 194 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label> <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason">Reason </label> <select name="reason" id="'.$this->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n"; 195 $expected .= '</li>'."\n"; 196 $expected .= '</ul>'."\n"; 197 $expected .= '<script type="text/javascript">'."\n"; 198 $expected .= '//<![CDATA['."\n"; 199 $expected .= 'jForms.getForm("").getControl("status").activate("new");'."\n"; 200 $expected .= '//]]>'."\n"; 201 $expected .= '</script>'; 202 ob_start();$this->builder->outputControl($choice);$out = ob_get_clean(); 203 $this->assertEqualOrDiff($expected, $out); 204 205 $this->form->getContainer()->data['status']='closed'; 206 $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n"; 207 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n"; 208 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label> <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom">Name</label> <input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n"; 209 $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n"; 210 $expected .= '</li>'."\n"; 211 $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_2" value="closed" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label> <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason">Reason </label> <select name="reason" id="'.$this->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n"; 212 $expected .= '</li>'."\n"; 213 $expected .= '</ul>'."\n"; 214 $expected .= '<script type="text/javascript">'."\n"; 215 $expected .= '//<![CDATA['."\n"; 216 $expected .= 'jForms.getForm("").getControl("status").activate("closed");'."\n"; 217 $expected .= '//]]>'."\n"; 218 $expected .= '</script>'; 219 ob_start();$this->builder->outputControl($choice);$out = ob_get_clean(); 220 $this->assertEqualOrDiff($expected, $out); 221 } 222 223 224 114 225 } 115 226
