Changeset 970
- Timestamp:
- 05/31/08 15:12:08 (6 months ago)
- Files:
-
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php (modified) (1 diff)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php (modified) (1 diff)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php (modified) (1 diff)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php (modified) (1 diff)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php (modified) (6 diffs)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php (modified) (6 diffs)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php (modified) (6 diffs)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php (modified) (6 diffs)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php (modified) (4 diffs)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php (modified) (4 diffs)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php (modified) (4 diffs)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php
r926 r970 147 147 public function check(){ 148 148 $this->container->errors = array(); 149 foreach($this-> controls as $name=>$ctrl){149 foreach($this->rootControls as $name=>$ctrl){ 150 150 if($this->container->isActivated($name)) 151 151 $ctrl->check(); branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php
r926 r970 147 147 public function check(){ 148 148 $this->container->errors = array(); 149 foreach($this-> controls as $name=>$ctrl){149 foreach($this->rootControls as $name=>$ctrl){ 150 150 if($this->container->isActivated($name)) 151 151 $ctrl->check(); branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php
r926 r970 147 147 public function check(){ 148 148 $this->container->errors = array(); 149 foreach($this-> controls as $name=>$ctrl){149 foreach($this->rootControls as $name=>$ctrl){ 150 150 if($this->container->isActivated($name)) 151 151 $ctrl->check(); branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php
r926 r970 147 147 public function check(){ 148 148 $this->container->errors = array(); 149 foreach($this-> controls as $name=>$ctrl){149 foreach($this->rootControls as $name=>$ctrl){ 150 150 if($this->container->isActivated($name)) 151 151 $ctrl->check(); branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php
r926 r970 527 527 public $type = 'groups'; 528 528 529 /** 530 * all child controls of the group 531 */ 529 532 protected $childControls = array(); 530 533 531 534 function check(){ 532 $ v = parent::check();535 $rv = null; 533 536 foreach($this->childControls as $ctrl) { 534 $ctrl->check($this); 535 } 536 return $v; 537 if(($rv2 = $ctrl->check())!==null) { 538 $rv = $rv2; 539 } 540 } 541 return $rv; 537 542 } 538 543 … … 572 577 573 578 /** 574 * choice579 * group 575 580 * @package jelix 576 581 * @subpackage forms … … 580 585 } 581 586 587 582 588 /** 583 589 * choice … … 589 595 public $type="choice"; 590 596 597 /** 598 * list of item. Each value is an array which contains corresponding controls of the item 599 * an item could not have controls, in this case its value is an empty array 600 */ 591 601 public $items = array(); 592 602 593 function addChildControl($control, $itemName = '') { 603 public $itemsNames = array(); 604 605 function check(){ 606 if(isset($this->items[$this->container->data[$this->ref]])) { 607 $rv = null; 608 foreach($this->items[$this->container->data[$this->ref]] as $ctrl) { 609 if (($rv2 = $ctrl->check()) !== null) { 610 $rv = $rv2; 611 } 612 } 613 return $rv; 614 } else { 615 return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; 616 } 617 } 618 619 function createItem($value, $label) { 620 $this->items[$value] = array(); 621 $this->itemsNames[$value]= $label; 622 } 623 624 function addChildControl($control, $itemValue = '') { 594 625 $this->childControls[$control->ref]=$control; 595 $this->items[$itemName][$control->ref] = $control; 596 } 626 $this->items[$itemValue][$control->ref] = $control; 627 } 628 597 629 598 630 function setData($value) { 599 631 parent::setData($value); 632 // we deactivate controls which are not selected 600 633 foreach($this->items as $item => $list) { 601 634 $ro = ($item != $value); … … 608 641 function setValueFromRequest($request) { 609 642 $this->setData($request->getParam($this->ref,'')); 610 foreach($this->childControls as $name=>$ctrl){611 if(!$this->container->isActivated($name) || $this->container->isReadOnly($name))612 continue;613 $ctrl->setValueFromRequest($request);614 } 615 } 616 } 617 618 /** 619 * choice643 if(isset($this->items[$this->container->data[$this->ref]])){ 644 foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 645 $ctrl->setValueFromRequest($request); 646 } 647 } 648 } 649 } 650 651 /** 652 * switch 620 653 * @package jelix 621 654 * @subpackage forms … … 623 656 class jFormsControlSwitch extends jFormsControlChoice { 624 657 public $type="switch"; 625 } 626 627 /** 628 * choice 629 * @package jelix 630 * @subpackage forms 631 */ 658 659 660 function setValueFromRequest($request) { 661 //$this->setData($request->getParam($this->ref,'')); 662 if(isset($this->items[$this->container->data[$this->ref]])){ 663 foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 664 $ctrl->setValueFromRequest($request); 665 } 666 } 667 } 668 } 669 670 /* 671 * repeat 672 * @package jelix 673 * @subpackage forms 674 */ 675 /* 632 676 class jFormsControlRepeat extends jFormsControlGroups { 633 677 public $type="repeat"; 634 } 635 678 }*/ 679 branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php
r926 r970 527 527 public $type = 'groups'; 528 528 529 /** 530 * all child controls of the group 531 */ 529 532 protected $childControls = array(); 530 533 531 534 function check(){ 532 $ v = parent::check();535 $rv = null; 533 536 foreach($this->childControls as $ctrl) { 534 $ctrl->check($this); 535 } 536 return $v; 537 if(($rv2 = $ctrl->check())!==null) { 538 $rv = $rv2; 539 } 540 } 541 return $rv; 537 542 } 538 543 … … 572 577 573 578 /** 574 * choice579 * group 575 580 * @package jelix 576 581 * @subpackage forms … … 580 585 } 581 586 587 582 588 /** 583 589 * choice … … 589 595 public $type="choice"; 590 596 597 /** 598 * list of item. Each value is an array which contains corresponding controls of the item 599 * an item could not have controls, in this case its value is an empty array 600 */ 591 601 public $items = array(); 592 602 593 function addChildControl($control, $itemName = '') { 603 public $itemsNames = array(); 604 605 function check(){ 606 if(isset($this->items[$this->container->data[$this->ref]])) { 607 $rv = null; 608 foreach($this->items[$this->container->data[$this->ref]] as $ctrl) { 609 if (($rv2 = $ctrl->check()) !== null) { 610 $rv = $rv2; 611 } 612 } 613 return $rv; 614 } else { 615 return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; 616 } 617 } 618 619 function createItem($value, $label) { 620 $this->items[$value] = array(); 621 $this->itemsNames[$value]= $label; 622 } 623 624 function addChildControl($control, $itemValue = '') { 594 625 $this->childControls[$control->ref]=$control; 595 $this->items[$itemName][$control->ref] = $control; 596 } 626 $this->items[$itemValue][$control->ref] = $control; 627 } 628 597 629 598 630 function setData($value) { 599 631 parent::setData($value); 632 // we deactivate controls which are not selected 600 633 foreach($this->items as $item => $list) { 601 634 $ro = ($item != $value); … … 608 641 function setValueFromRequest($request) { 609 642 $this->setData($request->getParam($this->ref,'')); 610 foreach($this->childControls as $name=>$ctrl){611 if(!$this->container->isActivated($name) || $this->container->isReadOnly($name))612 continue;613 $ctrl->setValueFromRequest($request);614 } 615 } 616 } 617 618 /** 619 * choice643 if(isset($this->items[$this->container->data[$this->ref]])){ 644 foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 645 $ctrl->setValueFromRequest($request); 646 } 647 } 648 } 649 } 650 651 /** 652 * switch 620 653 * @package jelix 621 654 * @subpackage forms … … 623 656 class jFormsControlSwitch extends jFormsControlChoice { 624 657 public $type="switch"; 625 } 626 627 /** 628 * choice 629 * @package jelix 630 * @subpackage forms 631 */ 658 659 660 function setValueFromRequest($request) { 661 //$this->setData($request->getParam($this->ref,'')); 662 if(isset($this->items[$this->container->data[$this->ref]])){ 663 foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 664 $ctrl->setValueFromRequest($request); 665 } 666 } 667 } 668 } 669 670 /* 671 * repeat 672 * @package jelix 673 * @subpackage forms 674 */ 675 /* 632 676 class jFormsControlRepeat extends jFormsControlGroups { 633 677 public $type="repeat"; 634 } 635 678 }*/ 679 branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php
r926 r970 527 527 public $type = 'groups'; 528 528 529 /** 530 * all child controls of the group 531 */ 529 532 protected $childControls = array(); 530 533 531 534 function check(){ 532 $ v = parent::check();535 $rv = null; 533 536 foreach($this->childControls as $ctrl) { 534 $ctrl->check($this); 535 } 536 return $v; 537 if(($rv2 = $ctrl->check())!==null) { 538 $rv = $rv2; 539 } 540 } 541 return $rv; 537 542 } 538 543 … … 572 577 573 578 /** 574 * choice579 * group 575 580 * @package jelix 576 581 * @subpackage forms … … 580 585 } 581 586 587 582 588 /** 583 589 * choice … … 589 595 public $type="choice"; 590 596 597 /** 598 * list of item. Each value is an array which contains corresponding controls of the item 599 * an item could not have controls, in this case its value is an empty array 600 */ 591 601 public $items = array(); 592 602 593 function addChildControl($control, $itemName = '') { 603 public $itemsNames = array(); 604 605 function check(){ 606 if(isset($this->items[$this->container->data[$this->ref]])) { 607 $rv = null; 608 foreach($this->items[$this->container->data[$this->ref]] as $ctrl) { 609 if (($rv2 = $ctrl->check()) !== null) { 610 $rv = $rv2; 611 } 612 } 613 return $rv; 614 } else { 615 return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; 616 } 617 } 618 619 function createItem($value, $label) { 620 $this->items[$value] = array(); 621 $this->itemsNames[$value]= $label; 622 } 623 624 function addChildControl($control, $itemValue = '') { 594 625 $this->childControls[$control->ref]=$control; 595 $this->items[$itemName][$control->ref] = $control; 596 } 626 $this->items[$itemValue][$control->ref] = $control; 627 } 628 597 629 598 630 function setData($value) { 599 631 parent::setData($value); 632 // we deactivate controls which are not selected 600 633 foreach($this->items as $item => $list) { 601 634 $ro = ($item != $value); … … 608 641 function setValueFromRequest($request) { 609 642 $this->setData($request->getParam($this->ref,'')); 610 foreach($this->childControls as $name=>$ctrl){611 if(!$this->container->isActivated($name) || $this->container->isReadOnly($name))612 continue;613 $ctrl->setValueFromRequest($request);614 } 615 } 616 } 617 618 /** 619 * choice643 if(isset($this->items[$this->container->data[$this->ref]])){ 644 foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 645 $ctrl->setValueFromRequest($request); 646 } 647 } 648 } 649 } 650 651 /** 652 * switch 620 653 * @package jelix 621 654 * @subpackage forms … … 623 656 class jFormsControlSwitch extends jFormsControlChoice { 624 657 public $type="switch"; 625 } 626 627 /** 628 * choice 629 * @package jelix 630 * @subpackage forms 631 */ 658 659 660 function setValueFromRequest($request) { 661 //$this->setData($request->getParam($this->ref,'')); 662 if(isset($this->items[$this->container->data[$this->ref]])){ 663 foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 664 $ctrl->setValueFromRequest($request); 665 } 666 } 667 } 668 } 669 670 /* 671 * repeat 672 * @package jelix 673 * @subpackage forms 674 */ 675 /* 632 676 class jFormsControlRepeat extends jFormsControlGroups { 633 677 public $type="repeat"; 634 } 635 678 }*/ 679 branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php
r926 r970 527 527 public $type = 'groups'; 528 528 529 /** 530 * all child controls of the group 531 */ 529 532 protected $childControls = array(); 530 533 531 534 function check(){ 532 $ v = parent::check();535 $rv = null; 533 536 foreach($this->childControls as $ctrl) { 534 $ctrl->check($this); 535 } 536 return $v; 537 if(($rv2 = $ctrl->check())!==null) { 538 $rv = $rv2; 539 } 540 } 541 return $rv; 537 542 } 538 543 … … 572 577 573 578 /** 574 * choice579 * group 575 580 * @package jelix 576 581 * @subpackage forms … … 580 585 } 581 586 587 582 588 /** 583 589 * choice … … 589 595 public $type="choice"; 590 596 597 /** 598 * list of item. Each value is an array which contains corresponding controls of the item 599 * an item could not have controls, in this case its value is an empty array 600 */ 591 601 public $items = array(); 592 602 593 function addChildControl($control, $itemName = '') { 603 public $itemsNames = array(); 604 605 function check(){ 606 if(isset($this->items[$this->container->data[$this->ref]])) { 607 $rv = null; 608 foreach($this->items[$this->container->data[$this->ref]] as $ctrl) { 609 if (($rv2 = $ctrl->check()) !== null) { 610 $rv = $rv2; 611 } 612 } 613 return $rv; 614 } else { 615 return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; 616 } 617 } 618 619 function createItem($value, $label) { 620 $this->items[$value] = array(); 621 $this->itemsNames[$value]= $label; 622 } 623 624 function addChildControl($control, $itemValue = '') { 594 625 $this->childControls[$control->ref]=$control; 595 $this->items[$itemName][$control->ref] = $control; 596 } 626 $this->items[$itemValue][$control->ref] = $control; 627 } 628 597 629 598 630 function setData($value) { 599 631 parent::setData($value); 632 // we deactivate controls which are not selected 600 633 foreach($this->items as $item => $list) { 601 634 $ro = ($item != $value); … … 608 641 function setValueFromRequest($request) { 609 642 $this->setData($request->getParam($this->ref,'')); 610 foreach($this->childControls as $name=>$ctrl){611 if(!$this->container->isActivated($name) || $this->container->isReadOnly($name))612 continue;613 $ctrl->setValueFromRequest($request);614 } 615 } 616 } 617 618 /** 619 * choice643 if(isset($this->items[$this->container->data[$this->ref]])){ 644 foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 645 $ctrl->setValueFromRequest($request); 646 } 647 } 648 } 649 } 650 651 /** 652 * switch 620 653 * @package jelix 621 654 * @subpackage forms … … 623 656 class jFormsControlSwitch extends jFormsControlChoice { 624 657 public $type="switch"; 625 } 626 627 /** 628 * choice 629 * @package jelix 630 * @subpackage forms 631 */ 658 659 660 function setValueFromRequest($request) { 661 //$this->setData($request->getParam($this->ref,'')); 662 if(isset($this->items[$this->container->data[$this->ref]])){ 663 foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 664 $ctrl->setValueFromRequest($request); 665 } 666 } 667 } 668 } 669 670 /* 671 * repeat 672 * @package jelix 673 * @subpackage forms 674 */ 675 /* 632 676 class jFormsControlRepeat extends jFormsControlGroups { 633 677 public $type="repeat"; 634 } 635 678 }*/ 679 branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php
r914 r970 29 29 protected $form; 30 30 protected $container; 31 function testStart() {31 function setUp() { 32 32 $this->container = new jFormsDataContainer('',''); 33 33 $this->form = new testCDForm('foo',$this->container); … … 124 124 $ctrl->required = false; 125 125 $this->form->addCtrl($ctrl); 126 126 127 127 $this->form->setData('nom',null); 128 128 $this->assertTrue($this->form->check()); … … 137 137 $ctrl2->primarySecret = 'nom'; 138 138 $this->form->addCtrl($ctrl2, false); 139 139 140 140 $this->form->setData('nom_confirm',''); 141 141 $this->assertTrue($this->form->check()); 142 142 143 143 $this->form->setData('nom','aaa'); 144 144 $this->assertFalse($this->form->check()); … … 181 181 $this->assertTrue($this->form->check()); 182 182 } 183 184 function testGroup() { 185 $group = new jFormsControlGroup('group'); 186 187 $ctrl = new jFormsControlInput('nom'); 188 $ctrl->required = false; 189 $group->addChildControl($ctrl); 190 191 $ctrl = new jFormsControlCheckboxes('categories'); 192 $ctrl->required = true; 193 $group->addChildControl($ctrl); 194 $this->form->addCtrl($group); 195 196 $this->assertFalse($this->form->check()); 197 198 $this->form->setData('categories',array('toto','titi')); 199 $this->assertTrue($this->form->check()); 200 201 $this->form->setData('nom', 'foo'); 202 $this->assertTrue($this->form->check()); 203 204 } 205 206 207 function testChoice() { 208 $choice = new jFormsControlChoice('choice'); 209 $choice->required = false; 210 211 $choice->createItem('item1','labelitem1'); 212 $choice->createItem('item2','labelitem2'); 213 $choice->createItem('item3','labelitem3'); 214 215 $ctrl = new jFormsControlInput('nom'); 216 $ctrl->required = false; 217 $choice->addChildControl($ctrl, 'item1'); 218 219 $ctrl = new jFormsControlCheckboxes('categories'); 220 $ctrl->required = true; 221 $choice->addChildControl($ctrl, 'item1'); 222 223 $ctrl = new jFormsControlinput('datenaissance'); 224 $ctrl->datatype= new jDatatypelocaledate(); 225 $choice->addChildControl($ctrl, 'item2'); 226 227 $this->form->addCtrl($choice); 228 229 $this->assertFalse($this->form->check()); 230 231 $this->form->setData('choice', 'foo'); 232 $this->assertFalse($this->form->check()); 233 234 $this->form->setData('choice', 'item3'); 235 $this->assertTrue($this->form->check()); 236 237 $this->form->setData('choice', 'item1'); 238 $this->assertFalse($this->form->check()); 239 240 $this->form->setData('categories','toto'); 241 $this->assertFalse($this->form->check()); 242 243 $this->form->setData('categories',array('toto')); 244 $this->assertTrue($this->form->check()); 245 246 $this->form->setData('categories',array('toto','titi')); 247 $this->assertTrue($this->form->check()); 248 249 $this->form->setData('choice', 'item2'); 250 $this->assertTrue($this->form->check()); 251 252 $this->form->setData('categories',''); 253 $this->assertTrue($this->form->check()); 254 255 } 183 256 } 184 257 branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php
r914 r970 29 29 protected $form; 30 30 protected $container; 31 function testStart() {31 function setUp() { 32 32 $this->container = new jFormsDataContainer('',''); 33 33 $this->form = new testCDForm('foo',$this->container); … … 124 124 $ctrl->required = false; 125 125 $this->form->addCtrl($ctrl); 126 126 127 127 $this->form->setData('nom',null); 128 128 $this->assertTrue($this->form->check()); … … 137 137 $ctrl2->primarySecret = 'nom'; 138 138 $this->form->addCtrl($ctrl2, false); 139 139 140 140 $this->form->setData('nom_confirm',''); 141 141 $this->assertTrue($this->form->check()); 142 142 143 143 $this->form->setData('nom','aaa'); 144 144 $this->assertFalse($this->form->check()); … … 181 181 $this->assertTrue($this->form->check()); 182 182 } 183 184 function testGroup() { 185 $group = new jFormsControlGroup('group'); 186 187 $ctrl = new jFormsControlInput('nom'); 188 $ctrl->required = false; 189 $group->addChildControl($ctrl); 190 191 $ctrl = new jFormsControlCheckboxes('categories'); 192 $ctrl->required = true; 193 $group->addChildControl($ctrl); 194 $this->form->addCtrl($group); 195 196 $this->assertFalse($this->form->check()); 197 198 $this->form->setData('categories',array('toto','titi')); 199 $this->assertTrue($this->form->check()); 200 201 $this->form->setData('nom', 'foo'); 202 $this->assertTrue($this->form->check()); 203 204 } 205 206 207 function testChoice() { 208 $choice = new jFormsControlChoice('choice'); 209 $choice->required = false; 210 211 $choice->createItem('item1','labelitem1'); 212 $choice->createItem('item2','labelitem2'); 213 $choice->createItem('item3','labelitem3'); 214 215 $ctrl = new jFormsControlInput('nom'); 216 $ctrl->required = false; 217 $choice->addChildControl($ctrl, 'item1'); 218 219 $ctrl = new jFormsControlCheckboxes('categories'); 220 $ctrl->required = true; 221 $choice->addChildControl($ctrl, 'item1'); 222 223 $ctrl = new jFormsControlinput('datenaissance'); 224 $ctrl->datatype= new jDatatypelocaledate(); 225 $choice->addChildControl($ctrl, 'item2'); 226 227 $this->form->addCtrl($choice); 228 229 $this->assertFalse($this->form->check()); 230 231 $this->form->setData('choice', 'foo'); 232 $this->assertFalse($this->form->check()); 233 234 $this->form->setData('choice', 'item3'); 235 $this->assertTrue($this->form->check()); 236 237 $this->form->setData('choice', 'item1'); 238 $this->assertFalse($this->form->check()); 239 240 $this->form->setData('categories','toto'); 241 $this->assertFalse($this->form->check()); 242 243 $this->form->setData('categories',array('toto')); 244 $this->assertTrue($this->form->check()); 245 246 $this->form->setData('categories',array('toto','titi')); 247 $this->assertTrue($this->form->check()); 248 249 $this->form->setData('choice', 'item2'); 250 $this->assertTrue($this->form->check()); 251 252 $this->form->setData('categories',''); 253 $this->assertTrue($this->form->check()); 254 255 } 183 256 } 184 257 branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php
r914 r970 29 29 protected $form; 30 30 protected $container; 31 function testStart() {31 function setUp() { 32 32 $this->container = new jFormsDataContainer('',''); 33 33 $this->form = new testCDForm('foo',$this->container); … … 124 124 $ctrl->required = false; 125 125 $this->form->addCtrl($ctrl); 126 126 127 127 $this->form->setData('nom',null); 128 128 $this->assertTrue($this->form->check()); … … 137 137 $ctrl2->primarySecret = 'nom'; 138 138 $this->form->addCtrl($ctrl2, false); 139 139 140 140 $this->form->setData('nom_confirm',''); 141 141 $this->assertTrue($this->form->check()); 142 142 143 143 $this->form->setData('nom','aaa'); 144 144 $this->assertFalse($this->form->check()); … … 181 181 $this->assertTrue($this->form->check()); 182 182 } 183 184 function testGroup() { 185 $group = new jFormsControlGroup('group'); 186 187 $ctrl = new jFormsControlInput('nom'); 188 $ctrl->required = false; 189 $group->addChildControl($ctrl); 190 191 $ctrl = new jFormsControlCheckboxes('categories'); 192 $ctrl->required = true; 193 $group->addChildControl($ctrl); 194 $this->form->addCtrl($group); 195 196 $this->assertFalse($this->form->check()); 197 198 $this->form->setData('categories',array('toto','titi')); 199 $this->assertTrue($this->form->check()); 200 201 $this->form->setData('nom', 'foo'); 202 $this->assertTrue($this->form->check()); 203 204 } 205 206 207 function testChoice() { 208 $choice = new jFormsControlChoice('choice'); 209 $choice->required = false; 210 211 $choice->createItem('item1','labelitem1'); 212 $choice->createItem('item2','labelitem2'); 213 $choice->createItem('item3','labelitem3'); 214 215 $ctrl = new jFormsControlInput('nom'); 216 $ctrl->required = false; 217 $choice->addChildControl($ctrl, 'item1'); 218 219 $ctrl = new jFormsControlCheckboxes('categories'); 220 $ctrl->required = true; 221 $choice->addChildControl($ctrl, 'item1'); 222 223 $ctrl = new jFormsControlinput('datenaissance'); 224 $ctrl->datatype= new jDatatypelocaledate(); 225 $choice->addChildControl($ctrl, 'item2'); 226 227 $this->form->addCtrl($choice); 228 229 $this->assertFalse($this->form->check()); 230 231 $this->form->setData('choice', 'foo'); 232 $this->assertFalse($this->form->check()); 233 234 $this->form->setData('choice', 'item3'); 235 $this->assertTrue($this->form->check()); 236 237 $this->form->setData('choice', 'item1'); 238 $this->assertFalse($this->form->check()); 239 240 $this->form->setData('categories','toto'); 241 $this->assertFalse($this->form->check()); 242 243 $this->form->setData('categories',array('toto')); 244 $this->assertTrue($this->form->check()); 245 246 $this->form->setData('categories',array('toto','titi')); 247 $this->assertTrue($this->form->check()); 248 249 $this->form->setData('choice', 'item2'); 250 $this->assertTrue($this->form->check()); 251 252 $this->form->setData('categories',''); 253 $this->assertTrue($this->form->check()); 254 255 } 183 256 } 184 257 branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php
r914 r970 29 29 protected $form; 30 30 protected $container; 31 function testStart() {31 function setUp() { 32 32 $this->container = new jFormsDataContainer('',''); 33 33 $this->form = new testCDForm('foo',$this->container); … … 124 124 $ctrl->required = false; 125 125 $this->form->addCtrl($ctrl); 126 126 127 127 $this->form->setData('nom',null); 128 128 $this->assertTrue($this->form->check()); … … 137 137 $ctrl2->primarySecret = 'nom'; 138 138 $this->form->addCtrl($ctrl2, false); 139 139 140 140 $this->form->setData('nom_confirm',''); 141 141 $this->assertTrue($this->form->check()); 142 142 143 143 $this->form->setData('nom','aaa'); 144 144 $this->assertFalse($this->form->check()); … … 181 181 $this->assertTrue($this->form->check()); 182 182 } 183 184 function testGroup() { 185 $group = new jFormsControlGroup('group'); 186 187 $ctrl = new jFormsControlInput('nom'); 188 $ctrl->required = false; 189 $group->addChildControl($ctrl); 190 191 $ctrl = new jFormsControlCheckboxes('categories'); 192 $ctrl->required = true; 193 $group->addChildControl($ctrl); 194 $this->form->addCtrl($group
