diff --git a/src/FormBuilder.php b/src/FormBuilder.php
index c701de9..bdfa63f 100644
--- a/src/FormBuilder.php
+++ b/src/FormBuilder.php
@@ -190,7 +190,7 @@ class FormBuilder
{
$this->model = $model;
}
-
+
/**
* Get the current model instance on the form builder.
*
@@ -871,7 +871,7 @@ class FormBuilder
return $this->getRadioCheckedState($name, $value, $checked);
default:
- return $this->getValueAttribute($name) === $value;
+ return $this->compareValues($name, $value);
}
}
@@ -924,7 +924,21 @@ class FormBuilder
return $checked;
}
- return $this->getValueAttribute($name) === $value;
+ return $this->compareValues($name, $value);
+ }
+
+ /**
+ * Determine if the provide value loosely compares to the value assigned to the field.
+ * Use loose comparison because Laravel model casting may be in affect and therefore
+ * 1 == true and 0 == false.
+ *
+ * @param string $name
+ * @param string $value
+ * @return bool
+ */
+ protected function compareValues($name, $value)
+ {
+ return $this->getValueAttribute($name) == $value;
}
/**
diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php
index dc98c81..4a846cb 100644
--- a/tests/FormBuilderTest.php
+++ b/tests/FormBuilderTest.php
@@ -658,6 +658,21 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('', $form4);
}
+ public function testFormRadioWithAttributeCastToBoolean()
+ {
+ $this->setModel(['itemA' => true, 'itemB' => false]);
+
+ $radio1 = $this->formBuilder->radio('itemA', 1);
+ $radio2 = $this->formBuilder->radio('itemA', 0);
+ $radio3 = $this->formBuilder->radio('itemB', 1);
+ $radio4 = $this->formBuilder->radio('itemB', 0);
+
+ $this->assertEquals('', $radio1);
+ $this->assertEquals('', $radio2);
+ $this->assertEquals('', $radio3);
+ $this->assertEquals('', $radio4);
+ }
+
public function testFormRadioRepopulation()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));