Skip to content

Commit

Permalink
showOnUpdateForm/showOnCreateForm
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Dec 9, 2022
1 parent ba44bda commit 6715289
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
5 changes: 4 additions & 1 deletion resources/views/base/form/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class="py-4 px-6 block focus:outline-none text-purple">
@foreach($resource->formComponents() as $field)
@if($field instanceof \Leeto\MoonShine\Decorations\Decoration)
{{ $resource->renderDecoration($field, $item) }}
@elseif($field instanceof \Leeto\MoonShine\Fields\Field && $field->showOnForm)
@elseif($field instanceof \Leeto\MoonShine\Fields\Field
&& $field->showOnForm
&& ($item->exists ? $field->showOnUpdateForm : $field->showOnCreateForm)
)
<x-moonshine::field-container :field="$field" :item="$item" :resource="$resource">
{{ $resource->renderField($field, $item) }}
</x-moonshine::field-container>
Expand Down
7 changes: 5 additions & 2 deletions resources/views/decorations/tab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
@foreach($decoration->fields() as $field)
@if($field instanceof \Leeto\MoonShine\Decorations\Decoration)
{{ $resource->renderDecoration($field, $item) }}
@elseif($field instanceof \Leeto\MoonShine\Fields\Field && $field->showOnForm)
@elseif($field instanceof \Leeto\MoonShine\Fields\Field
&& $field->showOnForm
&& ($item->exists ? $field->showOnUpdateForm : $field->showOnCreateForm)
)
<x-moonshine::field-container :field="$field" :item="$item" :resource="$resource">
{{ $resource->renderField($field, $item) }}
</x-moonshine::field-container>
@endif
@endforeach
</div>
</div>
56 changes: 56 additions & 0 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ abstract class Field implements HtmlViewable, HasAssets, HasExportViewValue, Has

public bool $showOnForm = true;

public bool $showOnCreateForm = true;

public bool $showOnUpdateForm = true;

protected Field|null $parent = null;

protected string $hint = '';
Expand Down Expand Up @@ -107,6 +111,58 @@ public function hideOnForm(mixed $condition = null): static
return $this;
}

/**
* Set field as show on create page, based on condition
*
* @param mixed $condition
* @return $this
*/
public function showOnCreate(mixed $condition = null): static
{
$this->showOnCreateForm = Condition::boolean($condition, true);

return $this;
}

/**
* Set field as hidden on create page, based on condition
*
* @param mixed $condition
* @return $this
*/
public function hideOnCreate(mixed $condition = null): static
{
$this->showOnCreateForm = Condition::boolean($condition, false);

return $this;
}

/**
* Set field as show on update page, based on condition
*
* @param mixed $condition
* @return $this
*/
public function showOnUpdate(mixed $condition = null): static
{
$this->showOnUpdateForm = Condition::boolean($condition, true);

return $this;
}

/**
* Set field as hidden on update page, based on condition
*
* @param mixed $condition
* @return $this
*/
public function hideOnUpdate(mixed $condition = null): static
{
$this->showOnUpdateForm = Condition::boolean($condition, false);

return $this;
}

/**
* Set field as visible in export report, based on condition
*
Expand Down

0 comments on commit 6715289

Please sign in to comment.