Skip to content

Commit

Permalink
New: Allow optional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tanthammar committed Aug 11, 2020
1 parent 1cfca3b commit 7c9d1a7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions resources/views/form-layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<div class="{{ $form_wrapper }}">
<div class="sm:grid sm:col-gap-4 sm:grid-cols-6 sm:space-y-0 {{ $rowgap }}">
@foreach($fields as $field)
@if(filled($field))
<div class="sm:col-span-{{ $field->colspan ?? 6 }}">
@if($field->view)
@include($field->view)
@else
@include('tall-forms::fields.' . $field->type)
@endif
</div>
@endif
@endforeach
</div>
<div class="w-full mt-8 border-t border-gray-200 pt-5">
Expand Down
2 changes: 1 addition & 1 deletion src/FormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function setFormProperties($model = null)
{
if ($model) $this->form_data = $model->toArray();
foreach ($this->fields() as $field) {
if (!isset($this->form_data[$field->name])) {
if (filled($field) && !isset($this->form_data[$field->name])) {
$array = in_array($field->type, ['checkboxes', 'file']);
$this->form_data[$field->name] = $field->default ?? ($array ? [] : null);
}
Expand Down

0 comments on commit 7c9d1a7

Please sign in to comment.