Skip to content
This repository
  • 2 commits
  • 2 files changed
  • 0 comments
  • 2 contributors
8  template/helper/Form.php
@@ -645,8 +645,8 @@ public function checkbox($name, array $options = array()) {
645 645
 		list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
646 646
 		list($scope, $options) = $this->_options($defaults, $options);
647 647
 
648  
-		if (!isset($options['checked']) && ($bound = $this->binding($key)->data)) {
649  
-			$options['checked'] = ($bound == $default);
  648
+		if (!isset($options['checked'])) {
  649
+			$options['checked'] = ($this->binding($key)->data == $default);
650 650
 		}
651 651
 		if ($scope['hidden']) {
652 652
 			$out = $this->hidden($name, array('value' => '', 'id' => false));
@@ -674,8 +674,8 @@ public function radio($name, array $options = array()) {
674 674
 		list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
675 675
 		list($scope, $options) = $this->_options($defaults, $options);
676 676
 
677  
-		if (!isset($options['checked']) && ($bound = $this->binding($name)->data)) {
678  
-			$options['checked'] = ($bound == $default);
  677
+		if (!isset($options['checked'])) {
  678
+			$options['checked'] = ($this->binding($name)->data == $default);
679 679
 		}
680 680
 
681 681
 		$options['value'] = $scope['value'];
50  tests/cases/template/helper/FormTest.php
@@ -396,8 +396,19 @@ public function testCheckboxGeneration() {
396 396
 		$this->assertTags($result, array(
397 397
 			array('input' => array('type' => 'hidden', 'value' => '', 'name' => 'foo')),
398 398
 			array('input' => array(
399  
-				'type' => 'checkbox', 'value' => '1', 'name' => 'foo',
400  
-				'checked' => 'checked', 'id' => 'MockFormPostFoo'
  399
+				'type' => 'checkbox', 'value' => '1', 'name' => 'foo', 'id' => 'MockFormPostFoo',
  400
+				'checked' => 'checked'
  401
+			))
  402
+		));
  403
+
  404
+		$record = new Record(array('model' => $this->_model, 'data' => array('foo' => false)));
  405
+		$this->form->create($record);
  406
+
  407
+		$result = $this->form->checkbox('foo');
  408
+		$this->assertTags($result, array(
  409
+			array('input' => array('type' => 'hidden', 'value' => '', 'name' => 'foo')),
  410
+			array('input' => array(
  411
+				'type' => 'checkbox', 'value' => '1', 'name' => 'foo', 'id' => 'MockFormPostFoo'
401 412
 			))
402 413
 		));
403 414
 
@@ -497,6 +508,17 @@ public function testCustomValueCheckbox() {
497 508
 				'type' => 'checkbox', 'value' => 'nose', 'name' => 'foo', 'id' => 'MockFormPostFoo'
498 509
 			))
499 510
 		));
  511
+
  512
+		$record = new Record(array('model' => $this->_model, 'data' => array('foo' => false)));
  513
+		$this->form->create($record);
  514
+		$result = $this->form->checkbox('foo', array('value' => '0'));
  515
+		$this->assertTags($result, array(
  516
+			array('input' => array('type' => 'hidden', 'value' => '', 'name' => 'foo')),
  517
+			array('input' => array(
  518
+				'type' => 'checkbox', 'value' => '0', 'name' => 'foo', 'id' => 'MockFormPostFoo',
  519
+				'checked' => 'checked'
  520
+			))
  521
+		));
500 522
 	}
501 523
 
502 524
 	public function testRadioGeneration() {
@@ -527,8 +549,18 @@ public function testRadioGeneration() {
527 549
 		$result = $this->form->radio('foo');
528 550
 		$this->assertTags($result, array(
529 551
 			array('input' => array(
530  
-				'type' => 'radio', 'value' => '1', 'name' => 'foo',
531  
-				'checked' => 'checked', 'id' => 'MockFormPostFoo'
  552
+				'type' => 'radio', 'value' => '1', 'name' => 'foo', 'id' => 'MockFormPostFoo',
  553
+				'checked' => 'checked'
  554
+			))
  555
+		));
  556
+
  557
+		$record = new Record(array('model' => $this->_model, 'data' => array('foo' => false)));
  558
+		$this->form->create($record);
  559
+
  560
+		$result = $this->form->radio('foo');
  561
+		$this->assertTags($result, array(
  562
+			array('input' => array(
  563
+				'type' => 'radio', 'value' => '1', 'name' => 'foo', 'id' => 'MockFormPostFoo'
532 564
 			))
533 565
 		));
534 566
 	}
@@ -605,6 +637,16 @@ public function testCustomValueRadio() {
605 637
 				'type' => 'checkbox', 'value' => 'nose', 'name' => 'foo', 'id' => 'MockFormPostFoo'
606 638
 			))
607 639
 		));
  640
+
  641
+		$record = new Record(array('model' => $this->_model, 'data' => array('foo' => false)));
  642
+		$this->form->create($record);
  643
+		$result = $this->form->radio('foo', array('value' => '0'));
  644
+		$this->assertTags($result, array(
  645
+			array('input' => array(
  646
+				'type' => 'radio', 'value' => '0',  'name' => 'foo',
  647
+				'id' => 'MockFormPostFoo', 'checked' => 'checked'
  648
+			))
  649
+		));
608 650
 	}
609 651
 
610 652
 	public function testSelectGeneration() {

No commit comments for this range

Something went wrong with that request. Please try again.