mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-01 15:09:33 +08:00
wip
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace Filament\Forms\Components;
|
||||
|
||||
use Filament\Forms\Form;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Traits\Tappable;
|
||||
|
||||
@@ -153,11 +152,6 @@ class Component
|
||||
return $this->getForm()->getLivewire();
|
||||
}
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return $this->getForm()->getModel();
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
@@ -190,7 +184,6 @@ class Component
|
||||
public function getSubform()
|
||||
{
|
||||
return Form::for($this->getLivewire())
|
||||
->model($this->getModel())
|
||||
->schema($this->getSchema());
|
||||
}
|
||||
|
||||
|
||||
@@ -12,14 +12,10 @@ class Form
|
||||
|
||||
protected $livewire;
|
||||
|
||||
protected $model;
|
||||
|
||||
protected $rules = [];
|
||||
|
||||
protected $schema = [];
|
||||
|
||||
protected $submitMethod = 'submit';
|
||||
|
||||
protected $validationAttributes = [];
|
||||
|
||||
public function __construct($livewire)
|
||||
@@ -76,11 +72,6 @@ class Form
|
||||
return $this->livewire;
|
||||
}
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function getRules()
|
||||
{
|
||||
$rules = $this->rules;
|
||||
@@ -99,11 +90,6 @@ class Form
|
||||
return $this->schema;
|
||||
}
|
||||
|
||||
public function getSubmitMethod()
|
||||
{
|
||||
return $this->submitMethod;
|
||||
}
|
||||
|
||||
public function getValidationAttributes()
|
||||
{
|
||||
$attributes = $this->validationAttributes;
|
||||
@@ -122,13 +108,6 @@ class Form
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function model($model)
|
||||
{
|
||||
$this->model = $model;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function rules($rules)
|
||||
{
|
||||
$this->rules = value($rules);
|
||||
@@ -147,13 +126,6 @@ class Form
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function submitMethod($method)
|
||||
{
|
||||
$this->submitMethod = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function validationAttributes($attributes)
|
||||
{
|
||||
$this->validationAttributes = $attributes;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="submit"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="submit"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="submit"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="submit"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<x-filament::app-content>
|
||||
<x-filament::card>
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="save"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x-filament::app-content>
|
||||
<x-filament::card>
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="create"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<x-filament::app-content class="space-y-6">
|
||||
<x-filament::card>
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="save"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div>
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="attach"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div>
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="create"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div>
|
||||
<form
|
||||
wire:submit.prevent="{{ $this->getForm()->getSubmitMethod() }}"
|
||||
wire:submit.prevent="save"
|
||||
class="space-y-6"
|
||||
>
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
@@ -21,9 +21,7 @@ class EditAccount extends Page
|
||||
public function getForm()
|
||||
{
|
||||
return static::getResource()::form(
|
||||
Form::for($this)
|
||||
->model(static::getModel())
|
||||
->submitMethod('save'),
|
||||
Form::for($this)->model(static::getModel()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,11 @@ class BelongsToSelect extends Select
|
||||
return parent::getLabel();
|
||||
}
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return $this->getForm()->getModel();
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
if ($this->isPreloaded() && $callback = $this->getOptions) {
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace Filament\Resources\Forms\Components;
|
||||
class Component extends \Filament\Forms\Components\Component
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Resources\Forms\Components\Concerns;
|
||||
|
||||
use Filament\Resources\Forms\Form;
|
||||
|
||||
trait CanServeResourceSubform
|
||||
{
|
||||
public function getSubform()
|
||||
{
|
||||
return Form::for($this->getLivewire())
|
||||
->model($this->getForm()->getModel())
|
||||
->schema($this->getSchema());
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,6 @@ namespace Filament\Resources\Forms\Components\Concerns;
|
||||
trait InteractsWithResource
|
||||
{
|
||||
use CanBeDependentOnResourceRecord;
|
||||
use CanServeResourceSubform;
|
||||
use ManipulatesResourceRecord;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace Filament\Resources\Forms\Components;
|
||||
class Fieldset extends \Filament\Forms\Components\Fieldset
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace Filament\Resources\Forms\Components;
|
||||
class Grid extends \Filament\Forms\Components\Grid
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace Filament\Resources\Forms\Components;
|
||||
class Group extends \Filament\Forms\Components\Group
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace Filament\Resources\Forms\Components;
|
||||
class Section extends \Filament\Forms\Components\Section
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace Filament\Resources\Forms\Components;
|
||||
class Tab extends \Filament\Forms\Components\Tab
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace Filament\Resources\Forms\Components;
|
||||
class Tabs extends \Filament\Forms\Components\Tabs
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace Filament\Resources\Forms\Components;
|
||||
class View extends \Filament\Forms\Components\View
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
|
||||
@@ -4,5 +4,17 @@ namespace Filament\Resources\Forms;
|
||||
|
||||
class Form extends \Filament\Forms\Form
|
||||
{
|
||||
//
|
||||
protected $model;
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function model($model)
|
||||
{
|
||||
$this->model = $model;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +51,7 @@ class CreateRecord extends Page
|
||||
public function getForm()
|
||||
{
|
||||
return static::getResource()::form(
|
||||
$this->form()
|
||||
->model(static::getModel())
|
||||
->submitMethod('create'),
|
||||
$this->form()->model(static::getModel()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,9 +59,7 @@ class EditRecord extends Page
|
||||
public function getForm()
|
||||
{
|
||||
return static::getResource()::form(
|
||||
$this->form()
|
||||
->model(static::getModel())
|
||||
->submitMethod('save'),
|
||||
$this->form()->model(static::getModel()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ class AttachRecord extends Component
|
||||
public function getForm()
|
||||
{
|
||||
return Form::for($this)
|
||||
->submitMethod('attach')
|
||||
->schema([
|
||||
Select::make('related')
|
||||
->label((string) Str::of($this->getRelationship())->singular()->ucfirst())
|
||||
|
||||
@@ -49,9 +49,7 @@ class CreateRecord extends Component
|
||||
public function getForm()
|
||||
{
|
||||
return $this->manager::form(
|
||||
Form::for($this)
|
||||
->model(get_class($this->owner->{$this->getRelationship()}()->getModel()))
|
||||
->submitMethod('create'),
|
||||
Form::for($this)->model(get_class($this->owner->{$this->getRelationship()}()->getModel())),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,7 @@ class EditRecord extends Component
|
||||
|
||||
public function getForm()
|
||||
{
|
||||
$form = Form::for($this)
|
||||
->model(get_class($this->owner->{$this->getRelationship()}()->getModel()))
|
||||
->submitMethod('save');
|
||||
|
||||
if ($this->record instanceof Model) {
|
||||
$form->record($this->record);
|
||||
}
|
||||
$form = Form::for($this)->model(get_class($this->owner->{$this->getRelationship()}()->getModel()));
|
||||
|
||||
return $this->manager::form($form);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user