laravel-form-builder
laravel-form-builder copied to clipboard
$field->prototype() not using custom template in Collection
I have a collection
field
$this->add('option_types', 'collection', [
'type' => 'form',
'template' => 'products.partials.option_types_field',
'options' => [
'class' => ProductOptionTypesForm::class,
'label' => false,
]
]);
class ProductOptionTypesForm extends Form
{
public function buildForm()
{
$this
->add('option_type', 'select', [
'label' => false,
])
->add('option_value', 'text', [
'attr' => [
'class' => 'option-value'
]
]);
}
}
And my custom template to generate a table of the option fields
<?php if ($showField): ?>
<?php foreach ((array)$options['children'] as $child): ?>
<tr class="option-row">
<td>
<div class="form-group">
<?php echo $child->getChild('option_type')->render([], false, true, false) ?>
</div>
</td>
<td>
<div class="form-group">
<?php echo $child->getChild('option_value')->render([], false, true, false) ?>
</div>
</td>
<td>
<ul class="segmented">
<li class="first-child">
<a href="#" class="btn remove-option" title="remove"><i class="fa fa-trash-o"></i></a>
</li>
</ul>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
The form generate correctly using my custom template when I call {!! form_widget($form->option_types) !!} but it always generate using default collection
template when I call form_widget($form->option_types->prototype())
Is this a bug or anything that I am doing wrongly?
@iainheng if i understood correctly, you need to pass custom template to the options
array, same where you put 'label' => false
.