Skip to content

Commit f57d941

Browse files
committed
Close formers#250 - Wrap appended buttons in special class in BS3
1 parent bbc1b2a commit f57d941

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 3.4.2
44

5+
- [add] Added the ability to specify multiple namespaces to look for fields in the MethodDispatcher
56
- [fix] Fixed some bug when fetching data from the request
67
- [fix] Fixed spaces in validation rules causing errors
78

src/Former/Form/Group.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,7 @@ protected function placeAround($items, $place)
460460
{
461461
// Iterate over the items and place them where they should
462462
foreach ((array) $items as $item) {
463-
464-
// Render the item if it's an object
465-
if (is_object($item) and method_exists($item, '__toString')) {
466-
$item = $item->__toString();
467-
}
468-
469-
// If the item is not a button, wrap it
470-
if (is_string($item) and !Str::startsWith($item, '<button')) {
471-
$item = $this->app['former.framework']->placeAround($item);
472-
}
473-
463+
$item = $this->app['former.framework']->placeAround($item);
474464
$this->{$place}[] = $item;
475465
}
476466
}

src/Former/Framework/TwitterBootstrap.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ public function createIcon($iconType, $attributes = array(), $iconSettings = arr
281281
*/
282282
public function placeAround($item)
283283
{
284+
// Render object
285+
if (is_object($item) and method_exists($item, '__toString')) {
286+
$item = $item->__toString();
287+
}
288+
289+
// Return unwrapped if button
290+
if (strpos($item, '<button') !== false) {
291+
return $item;
292+
}
293+
284294
return Element::create('span', $item)->addClass('add-on');
285295
}
286296

src/Former/Framework/TwitterBootstrap3.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,15 @@ public function createDisabledField(Field $field)
331331
*/
332332
public function placeAround($item)
333333
{
334-
return Element::create('span', $item)->addClass('input-group-addon');
334+
// Render object
335+
if (is_object($item) and method_exists($item, '__toString')) {
336+
$item = $item->__toString();
337+
}
338+
339+
// Get class to use
340+
$class = (strpos($item, '<button') !== false) ? 'btn' : 'addon';
341+
342+
return Element::create('span', $item)->addClass('input-group-'.$class);
335343
}
336344

337345
/**

tests/Framework/TwitterBootstrap3Test.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,11 @@ public function testAddFormControlClassToInlineActionsBlock()
191191
$this->former->close();
192192
}
193193

194+
public function testButtonsAreWrappedInSpecialClass()
195+
{
196+
$button = $this->former->text('foo')->append($this->former->button('Search'))->wrapAndRender();
197+
$matcher = '<span class="input-group-btn"><button class="btn" type="button">Search</button></span>';
198+
199+
$this->assertContains($matcher, $button);
200+
}
194201
}

0 commit comments

Comments
 (0)