Closed foxycode closed 8 years ago
Remove button shows only if user can delete some input (the same applies for second button, but the other way around).
Usage:
<td colspan="3" class="text-right">
{foreach $form['metadata']->getButtons() as $button}
{input $button class => 'btn btn-primary'}
{/foreach}
</td>
or (current commit)
{if $btn = $form['metadata']->getRemoveButton()}
{input $btn class => 'btn btn-primary'}
{/if}
{if $btn = $form['metadata']->getCreateButton()}
{input $btn class => 'btn btn-primary'}
{/if}
off topic:
Input macro accepts also object, so better is:
<tr n:foreach="$form['metadata']->getContainers() as $id => $container">
<td n:foreach="$container->components as $name => $component" n:class="$component->name === 'vps_metadata_id' ? hide">
{input metadata-$id-$name class => 'form-control'}
<span class="help-block" style="color:#a94442" n:foreach="$component->errors as $error">{$error}</span>
</td>
</tr>
@MartkCz Thans for fast answer. I solved it with ofset right now, because I want different button classes after all:
<td colspan="3" class="text-right">
{ifset $form['metadata']['multiplier_remover']}{input $form['metadata']['multiplier_remover'] class => 'btn btn-danger'}{/ifset}
{input $form['metadata']['multiplier_creator'] class => 'btn btn-success'}
</td>
But there must be error. Delete button is missing if I have one containers even if I have copies set to 0. I need to be able remove last container too.
Nice feature would be if remove buttons were on every line so I could remove one line in middle of others.
I don't understand last example, it seems same as mine.
But there must be error. Delete button is missing if I have one containers even if I have copies set to 0. I need to be able remove last container too.
$multiplier->setMinCopies(0);
Nice feature would be if remove buttons were on every line so I could remove one line in middle of others.
I will look at it
@MartkCz With setMinCopies
ti now works. Why I need to call it and this isn't enought?
$metadata = $form->addMultiplier('metadata', [$this, 'addMetadata'], 0, 10);
There is probably new bug introduced. When I don't set maxCopies
there is no add button wven with zero items.
Can you try dev version? You don't have to set min copies. Remove buttons added to each container.
@MartkCz Great. Almost everything works. I have last issue I hope.
I have some initial data:
/** @var \WebChemistry\Forms\Controls\Multiplier $metadata */
$metadata = $form->addMultiplier('metadata', [$this, 'addMetadata'], 0);
$metadata->addCreateButton('Přidat');
$metadata->addRemoveButton('Odebrat');
if (!$this->vps) {
$metadataValues = [
[
'name' => 'root_authorized_keys',
'value' => 'test',
],
[
'name' => 'user-script',
'value' => 'test2',
],
];
$metadata->setDefaults($metadataValues);
} else {
$metadata->setDefaults(array_map('iterator_to_array',
iterator_to_array($this->vps->related('vps_metadata'))));
}
Now when I remove both rows and click on add button, both previous rows will appear again (empty) and I get total 3 rows now.
Thank you for all reports. I fixed it in master and added feature.
Can you please add manual rendering example? I can't get remove button to work. I got this error:
Component with name 'multiplier_remover' does not exist
.Form code:
My template: