Skip to content

Commit

Permalink
Fix Former::plaintext() with Bootstrap 4 (#602)
Browse files Browse the repository at this point in the history
Replace 'form-control-static' CSS class with 'form-control-plaintext'

Usage with Laravel:

{!! Former::open()->method('GET') !!}
  {!! Former::plaintext('test_static')->value('Plain Text') !!}
{!! Former::close() !!}

Reference:
https://getbootstrap.com/docs/4.5/components/forms/#readonly-plain-text
  • Loading branch information
tortuetorche authored Jan 21, 2021
1 parent 2c25bef commit 272bddf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Former/Framework/TwitterBootstrap4.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function getUneditableClasses()
*/
public function getPlainTextClasses()
{
return 'form-control-static';
return 'form-control-plaintext';
}

/**
Expand Down
43 changes: 43 additions & 0 deletions tests/Fields/PlainTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ public function matchPlainTextInput()
);
}

/**
* Matches an plain text input as a p tag
*
* @return array
*/
public function matchPlainTextInputWithBS4()
{
return array(
'tag' => 'div',
'content' => 'bar',
'attributes' => array(
'class' => 'form-control-plaintext',
),
);
}

/**
* Matches an plain text input as a div tag
*
Expand Down Expand Up @@ -126,6 +142,21 @@ protected function formStaticGroup(
return $this->formGroup($input, $label);
}

/**
* Matches a Form Static Group
*
* @param string $input
* @param string $label
*
* @return boolean
*/
protected function formStaticGroupForBS4(
$input = '<div class="form-control-plaintext" id="foo">bar</div>',
$label = '<label for="" class="col-form-label col-lg-2 col-sm-4">Foo</label>'
) {
return $this->formGroupWithBS4($input, $label);
}

/**
* Matches a Form Static Group with HTML value escaped
*
Expand Down Expand Up @@ -188,6 +219,18 @@ public function testCanCreatePlainTextFieldsWithBS3()
$this->assertEquals($matcher, $input);
}

public function testCanCreatePlainTextFieldsWithBS4()
{
$this->former->framework('TwitterBootstrap4');
$input = $this->former->plaintext('foo')->value('bar')->__toString();

$this->assertHTML($this->matchPlainLabelWithBS3(), $input);
$this->assertHTML($this->matchPlainTextInputWithBS4(), $input);

$matcher = $this->formStaticGroupForBS4();
$this->assertEquals($matcher, $input);
}

public function testCanCreatePlainTextFieldsWithHtmlValueEscaped()
{
$this->former->framework('TwitterBootstrap3');
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCases/FormerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,21 @@ protected function formGroup(
return '<div class="form-group">'.$label.'<div class="col-lg-10 col-sm-8">'.$input.'</div></div>';
}

/**
* Matches a Form Group
*
* @param string $input
* @param string $label
*
* @return boolean
*/
protected function formGroupWithBS4(
$input = '<input type="text" name="foo" id="foo">',
$label = '<label for="foo" class="col-form-label col-lg-2 col-sm-4">Foo</label>'
) {
return '<div class="form-group row">'.$label.'<div class="col-lg-10 col-sm-8">'.$input.'</div></div>';
}

/**
* Matches a required Control Group
*
Expand Down

0 comments on commit 272bddf

Please sign in to comment.