You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.6 KiB

<?php if ($showLabel && $showField): ?>
<?php if ($options['wrapper'] !== false): ?>
<div <?= $options['wrapperAttrs'] ?> >
<?php endif; ?>
<?php endif; ?>
<?php if ($showLabel && $options['label'] !== false && $options['label_show']): ?>
<?= Form::customLabel($name, $options['label'], $options['label_attr']) ?>
<?php endif; ?>
<?= config("laravel-form-builder.inline") && !isset($options["pure"]) ? '<div class="controls col-sm-10">' : "" ?>
<?php if ($showField): ?>
<?php
$tbody = "";
foreach ((array)$options['children'] as $child) {
$row = "<tr><td><button onclick=\"$(this).parent().parent().remove()\" class=\"btn btn-sm btn-secondary\"><i class=\"mdi mdi-delete-forever\"></i></button>%s</td>%s</tr>";
$hiddens = [];
$fields = [];
foreach ($child->getFields() as $field) {
$type = $field->getType();
if (in_array($type, ["submit", "reset", "button", "buttongroup", "collection", "form"])) {
continue;
}
if ($type == "hidden") {
$hiddens[] = trim(str_replace(["\r\n", "\n", "\r"], "", form_widget($field)));
} else {
$fields[] = "<td class=\"form-group\">" . trim(str_replace(["\r\n", "\n", "\r"], "", form_widget($field))) . "</td>";
}
}
$row = sprintf($row, implode("", $hiddens), implode("", $fields));
$tbody .= $row;
}
$thead = "<tr><td><button onclick=\"addCollectionRow(this)\" type=\"button\" class=\"btn btn-sm btn-info\"><i class=\"mdi mdi-plus-box\"></i></button></td>%s</tr>";
$prototype = "<tr><td><button type=\"button\" class=\"btn btn-sm btn-secondary\" onclick=\"$(this).parent().parent().remove()\"><i class=\"mdi mdi-delete-forever\"></i></button>%s</td>%s</tr>";
$hiddens = [];
$labels = [];
$fields = [];
foreach (Arr::first((array)$options['children'])->getFields() as $field) {
$field->setOptions(["value" => null, "selected" => null]);
$type = $field->getType();
if (in_array($type, ["submit", "reset", "button", "buttongroup", "collection", "form"])) {
continue;
}
if ($type == "hidden") {
$hiddens[] = trim(str_replace(["\r\n", "\n", "\r"], "", form_widget($field)));
} else {
$labels[] = "<td style='white-space: nowrap; min-width: 80px;'>" . $field->getOptions()["label"] . "</td>";
$fields[] = "<td class=\"form-group\">" . trim(str_replace(["\r\n", "\n", "\r", "col-10"], "", form_widget($field))) . "</td>";
}
}
$thead = sprintf($thead, implode("", $labels));
$prototype = sprintf($prototype, implode("", $hiddens), implode("", $fields));
?>
<div class="pl-0 pr-0">
<table class="table table-bordered" data-rows="<?= count((array)$options['children']) ?>"
data-prototype='<?= str_replace("{$name}[0]", "{$name}[__NAME__]", $prototype) ?>'>
<thead>
<?= $thead ?>
</thead>
<tbody>
<?= $tbody ?>
</tbody>
</table>
<?php include 'help_block.php' ?>
</div>
<?php endif; ?>
<?= config("laravel-form-builder.inline") && !isset($options["pure"]) ? '</div>' : "" ?>
<?php include 'errors.php' ?>
<?php if ($showLabel && $showField): ?>
<?php if ($options['wrapper'] !== false): ?>
</div>
<?php endif; ?>
<?php endif; ?>