diff --git a/composer.json b/composer.json index f19599f..3a3224d 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "license": "MIT", "require": { "php": ">=5.4.0", - "adamwathan/form": "^0.8" + "adamwathan/form": "dev-aw-html5-boolean-attributes" }, "require-dev": { "phpunit/phpunit": "3.7.*", diff --git a/src/AdamWathan/BootForms/BasicFormBuilder.php b/src/AdamWathan/BootForms/BasicFormBuilder.php index 5e6b9f6..6a9cd7d 100644 --- a/src/AdamWathan/BootForms/BasicFormBuilder.php +++ b/src/AdamWathan/BootForms/BasicFormBuilder.php @@ -38,7 +38,11 @@ protected function wrap($group) public function text($label, $name, $value = null) { - $control = $this->builder->text($name)->value($value); + $control = $this->builder->text($name); + + if ($value !== null) { + $control->value($value); + } return $this->formGroup($label, $name, $control); } @@ -129,23 +133,34 @@ public function textarea($label, $name) public function date($label, $name, $value = null) { - $control = $this->builder->date($name)->value($value); + $control = $this->builder->date($name); + + if ($value !== null) { + $control->value($value); + } return $this->formGroup($label, $name, $control); } public function email($label, $name, $value = null) { - $control = $this->builder->email($name)->value($value); + $control = $this->builder->email($name); + + if ($value !== null) { + $control->value($value); + } return $this->formGroup($label, $name, $control); } public function file($label, $name, $value = null) { - $control = $this->builder->file($name)->value($value); + $control = $this->builder->file($name)->id($name); $label = $this->builder->label($label, $name)->addClass('control-label')->forId($name); - $control->id($name); + + if ($value !== null) { + $control->value($value); + } $formGroup = new FormGroup($label, $control); @@ -160,7 +175,8 @@ public function file($label, $name, $value = null) public function inputGroup($label, $name, $value = null) { $control = new InputGroup($name); - if (!is_null($value) || !is_null($value = $this->getValueFor($name))) { + + if ($value !== null || ($value = $this->getValueFor($name)) !== null) { $control->value($value); } diff --git a/src/AdamWathan/BootForms/HorizontalFormBuilder.php b/src/AdamWathan/BootForms/HorizontalFormBuilder.php index 21ee408..3653312 100644 --- a/src/AdamWathan/BootForms/HorizontalFormBuilder.php +++ b/src/AdamWathan/BootForms/HorizontalFormBuilder.php @@ -114,13 +114,15 @@ public function radio($label, $name, $value = null) public function file($label, $name, $value = null) { - $control = $this->builder->file($name)->value($value); + $control = $this->builder->file($name)->id($name); $label = $this->builder->label($label, $name) ->addClass($this->getLabelClass()) ->addClass('control-label') ->forId($name); - $control->id($name); + if ($value !== null) { + $control->value($value); + } $formGroup = new HorizontalFormGroup($label, $control, $this->getControlSizes()); diff --git a/tests/BasicFormBuilderTest.php b/tests/BasicFormBuilderTest.php index b24e6c8..fd6f370 100644 --- a/tests/BasicFormBuilderTest.php +++ b/tests/BasicFormBuilderTest.php @@ -254,14 +254,14 @@ public function testRenderCheckboxWithOldInput() $this->builder->setOldInputProvider($oldInput); - $expected = '
'; + $expected = '
'; $result = $this->form->checkbox('Agree to Terms', 'terms')->render(); $this->assertEquals($expected, $result); } public function testRenderCheckboxChecked() { - $expected = '
'; + $expected = '
'; $result = $this->form->checkbox('Agree to Terms', 'terms')->check()->render(); $this->assertEquals($expected, $result); } @@ -293,7 +293,7 @@ public function testRenderRadioWithOldInput() $this->builder->setOldInputProvider($oldInput); - $expected = '
'; + $expected = '
'; $result = $this->form->radio('Red', 'color', 'red')->render(); $this->assertEquals($expected, $result); } @@ -352,7 +352,7 @@ public function testRenderInlineCheckboxFallback() public function testRenderInlineCheckboxFallbackWithChaining() { - $expected = ''; + $expected = ''; $result = $this->form->inlineCheckbox('Checkit!', 'DJ')->value('meal')->chain('link')->check()->render(); $this->assertEquals($expected, $result); } @@ -366,7 +366,7 @@ public function testRenderInlineCheckboxModifier() public function testRenderInlineCheckboxModifierWithChaining() { - $expected = ''; + $expected = ''; $result = $this->form->checkbox('Checkit!', 'DJ')->inline()->value('meal')->chain('link')->check()->render(); $this->assertEquals($expected, $result); } @@ -380,7 +380,7 @@ public function testRenderInlineRadioFallback() public function testRenderInlineRadioFallbackWithChaining() { - $expected = ''; + $expected = ''; $result = $this->form->inlineRadio('Canada Red', 'colour')->chain('link')->check()->render(); $this->assertEquals($expected, $result); } @@ -394,14 +394,14 @@ public function testRenderInlineRadioModifier() public function testRenderInlineRadioModifierWithChaining() { - $expected = ''; + $expected = ''; $result = $this->form->radio('Canada Red', 'colour')->inline()->chain('link')->check()->render(); $this->assertEquals($expected, $result); } public function testRenderInlineModifierOnUnsupportedElement() { - $expected = '
'; + $expected = '
'; $result = $this->form->text('Name', 'name')->inline()->render(); $this->assertEquals($expected, $result); } diff --git a/tests/HorizontalFormBuilderTest.php b/tests/HorizontalFormBuilderTest.php index 43847c0..5ef026e 100644 --- a/tests/HorizontalFormBuilderTest.php +++ b/tests/HorizontalFormBuilderTest.php @@ -248,14 +248,14 @@ public function testRenderCheckboxWithOldInput() $this->builder->setOldInputProvider($oldInput); - $expected = '
'; + $expected = '
'; $result = $this->form->checkbox('Agree to Terms', 'terms')->render(); $this->assertEquals($expected, $result); } public function testRenderCheckboxChecked() { - $expected = '
'; + $expected = '
'; $result = $this->form->checkbox('Agree to Terms', 'terms')->check()->render(); $this->assertEquals($expected, $result); } @@ -294,7 +294,7 @@ public function testRenderRadioWithOldInput() $this->builder->setOldInputProvider($oldInput); - $expected = '
'; + $expected = '
'; $result = $this->form->radio('Red', 'color', 'red')->render(); $this->assertEquals($expected, $result); } diff --git a/tests/InputGroupTest.php b/tests/InputGroupTest.php index 6a15ef4..3795045 100644 --- a/tests/InputGroupTest.php +++ b/tests/InputGroupTest.php @@ -42,12 +42,6 @@ public function testCanRenderWithValue() $expected = '
'; $result = $input->render(); $this->assertEquals($expected, $result); - - $input = new InputGroup('test'); - $input = $input->value(null); - $expected = '
'; - $result = $input->render(); - $this->assertEquals($expected, $result); } public function testDefaultValue()