Skip to content

Commit 3a1780b

Browse files
authored
Merge pull request #15 from dipcode-software/feat/option-value-empty
Changed Select option to dont render value if it is empty
2 parents 9e2a8b7 + 18466ff commit 3a1780b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [2.0.1] - 2017-12-11
8+
### Changed
9+
- Loading `Twig` classes with psr-4 mode;
10+
- Select `option` tag don't render `value` if it is empty.
11+
712
## [2.0.0] - 2017-12-11
813
### Added
914
- Documentation of package;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<option value="{{value|e}}"{% include 'attrs.html' with attrs %}>{{label|e}}</option>
1+
<option {% if value is not empty %}value="{{value|e}}"{% endif %}{% include 'attrs.html' with attrs %}>{{label|e}}</option>

tests/unit/Widgets/SelectTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,21 @@ public function testRenderOtherSelected()
5151

5252
$this->assertXmlStringEqualsXmlString($expected, $widget->render("name", "option3"));
5353
}
54+
55+
public function testRenderOptionWithouValue()
56+
{
57+
$widget = new Select([
58+
"" => "",
59+
"option2" => "option2",
60+
"option3" => "option3",
61+
]);
62+
63+
$expected = '<select id="id_name" name="name">' .
64+
'<option></option>' .
65+
'<option value="option2">option2</option>' .
66+
'<option value="option3" selected="selected">option3</option>' .
67+
'</select>';
68+
69+
$this->assertXmlStringEqualsXmlString($expected, $widget->render("name", "option3"));
70+
}
5471
}

0 commit comments

Comments
 (0)