-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customizable column widths for horizontal Bootstrap forms
- Loading branch information
1 parent
fd8627c
commit d71fa5a
Showing
22 changed files
with
221 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Contributte\Forms\Rendering; | ||
|
||
use Nette\Forms\Rendering\DefaultFormRenderer; | ||
|
||
class AbstractBootstrapHorizontalRenderer extends DefaultFormRenderer | ||
{ | ||
|
||
/** @var int */ | ||
protected $colsLabel = 3; | ||
|
||
/** @var int */ | ||
protected $colsControl = 9; | ||
|
||
public function setColumns(int $colsLabel, int $colsControl): void | ||
{ | ||
$this->colsLabel = $colsLabel; | ||
$this->colsControl = $colsControl; | ||
} | ||
|
||
protected function getValue(string $name) | ||
{ | ||
$value = parent::getValue($name); | ||
if (is_string($value)) { | ||
$value = $this->replacePlaceholders($value); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
protected function replacePlaceholders(string $value): string | ||
{ | ||
$value = str_replace('%colsLabel%', (string) $this->colsLabel, $value); | ||
$value = str_replace('%colsControl%', (string) $this->colsControl, $value); | ||
return $value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Contributte\Forms\Rendering; | ||
|
||
use Nette\Utils\Html; | ||
|
||
class Helpers | ||
{ | ||
|
||
public static function htmlClassContains(Html $html, string $contains): bool | ||
{ | ||
/** @var string|string[]|null $class */ | ||
$class = $html->getAttribute('class'); | ||
if (is_array($class)) { | ||
$class = implode(' ', array_keys($class)); | ||
} | ||
|
||
return $class !== null && mb_strpos($class, $contains) !== false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/cases/Rendering/expected/bootstrap3horizontal.cols.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<form action="" method="post" novalidate class="form-horizontal"> | ||
|
||
<div> | ||
<div class="form-group"> | ||
<div class="col-sm-2 control-label"><label for="frm-text1">Text 1</label></div> | ||
|
||
<div class="col-sm-10"><input type="text" name="text1" class="form-control text" id="frm-text1"></div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-2 control-label"><label for="frm-text2">Text 2</label></div> | ||
|
||
<div class="col-sm-10"><input type="text" name="text2" class="my-text form-control text" id="frm-text2"></div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-2 control-label"><label for="frm-select">Select</label></div> | ||
|
||
<div class="col-sm-10"><select name="select" class="form-control" id="frm-select"><option value="1">Option 1</option><option value="2">Option 2</option></select></div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-2 control-label"></div> | ||
|
||
<div class="col-sm-10"><div class="checkbox"><label for="frm-checkbox"><input type="checkbox" name="checkbox" id="frm-checkbox">Checkbox</label></div></div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-2 control-label"></div> | ||
|
||
<div class="col-sm-10"><input type="submit" name="button" class="my-button btn btn-primary button" value="Button"></div> | ||
</div> | ||
</div> | ||
|
||
</form> |
Oops, something went wrong.