cakephp3-bootstrap-helpers
cakephp3-bootstrap-helpers copied to clipboard
Group multiple input in the same row
Hello there,
First, thanks for releasing this Plugin.
Is is possible to group multiple input inside the same row ? For exemple, if I want to show 2 input in the same row, I use the following code :
<div class="row">
<?= $this->Form->input('name', [
"label" => false,
"type" => "text",
'templates' => [
'inputContainer' => '<div class="col-lg-6">{{content}}</div>'
],
]);
?>
<?= $this->Form->input('surname', [
"label" => false,
"type" => "text",
'templates' => [
'inputContainer' => '<div class="col-lg-6">{{content}}</div>'
],]);
?>
</div>
Am i missing something or is the only way ?
Thanks in advance
There is no built-in way to create form with multiple column, but you should not modify the inputContainer template, or at least keep the standard class.
The right way to do what you want is to insert input into a layout:
<div class="row">
<div class="col-lg-6">
<?= $this->Form->input('name', [
"label" => false,
"type" => "text"
]); ?>
</div>
<div class="col-lg-6">
<?= $this->Form->input('surname', [
"label" => false,
"type" => "text"
]); ?>
</div>
</div>
CakePHP has a inputs methods to generate multiple inputs in a fieldset. I will probably extend it to all multiple columns in a future version, so something like that:
echo $this->Form->inputs([
'name' => [
'label' => false,
'type' => text
],
'surname' => [
'label' => false,
'type' => text
]
]);
Would generate:
<fieldset class="row">
<div class="col-md-6">
...
</div>
<div class="col-md-6">
...
</div>
</fieldset>