diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php
index 1d40f68..00562b6 100755
--- a/src/HtmlBuilder.php
+++ b/src/HtmlBuilder.php
@@ -441,11 +441,13 @@ class HtmlBuilder
*/
protected function attributeElement($key, $value)
{
- // For numeric keys we will assume that the key and the value are the same
- // as this will convert HTML attributes such as "required" to a correct
- // form like required="required" instead of using incorrect numerics.
+ // For numeric keys we will assume that the value is a boolean attribute
+ // where the presence of the attribute represents a true value and the
+ // absence represents a false value.
+ // This will convert HTML attributes such as "required" to a correct
+ // form instead of using incorrect numerics.
if (is_numeric($key)) {
- $key = $value;
+ return $value;
}
// Treat boolean attributes as HTML properties
diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php
index 05ebdc8..8f3d957 100644
--- a/tests/FormBuilderTest.php
+++ b/tests/FormBuilderTest.php
@@ -11,6 +11,10 @@ use Mockery as m;
class FormBuilderTest extends PHPUnit_Framework_TestCase
{
+ /**
+ * @var FormBuilder
+ */
+ private $formBuilder;
/**
* @var FormBuilder
@@ -573,6 +577,15 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('', $form3);
}
+ public function testBooleanAttributes()
+ {
+ $input = $this->formBuilder->text('test', null, ['disabled']);
+ $this->assertEquals('', $input);
+
+ $input = $this->formBuilder->textarea('test', null, ['readonly']);
+ $this->assertEquals('', $input);
+ }
+
protected function setModel(array $data, $object = true)
{
if ($object) {