Skip to content

Commit 26231c2

Browse files
committed
Separate form data for create and update
1 parent 0c3eee9 commit 26231c2

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/Filament/Pages/KanbanBoardPage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function updating()
3434
/**
3535
* Set the field that stores the column value.
3636
*
37+
* @param string $field
3738
* @return KanbanBoardPage
3839
*/
3940
public function columnField(string $field): static
@@ -58,6 +59,7 @@ public function columns(array $columns): static
5859
/**
5960
* Set the title field for the Kanban cards.
6061
*
62+
* @param string $field
6163
* @return KanbanBoardPage
6264
*/
6365
public function titleField(string $field): static
@@ -70,6 +72,7 @@ public function titleField(string $field): static
7072
/**
7173
* Set the description field for the Kanban cards.
7274
*
75+
* @param string $field
7376
* @return KanbanBoardPage
7477
*/
7578
public function descriptionField(string $field): static
@@ -106,6 +109,7 @@ public function columnColors(?array $colors = null): static
106109
/**
107110
* Set the order field for the Kanban board.
108111
*
112+
* @param string $field
109113
* @return KanbanBoardPage
110114
*/
111115
public function orderField(string $field): static
@@ -118,6 +122,7 @@ public function orderField(string $field): static
118122
/**
119123
* Set the label for individual cards.
120124
*
125+
* @param string $label
121126
* @return KanbanBoardPage
122127
*/
123128
public function cardLabel(string $label): static

src/Livewire/KanbanBoard.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,16 @@ class KanbanBoard extends Component implements HasForms
8282
public array $searchable = [];
8383

8484
/**
85-
* Card data for form operations.
85+
* Card data for create form operations.
8686
*/
8787
#[Validate]
88-
public array $recordData = [];
88+
public array $createRecordData = [];
89+
90+
/**
91+
* Card data for edit form operations.
92+
*/
93+
#[Validate]
94+
public array $editRecordData = [];
8995

9096
/**
9197
* Number of cards to load when clicking "load more".
@@ -201,7 +207,7 @@ public function createRecordForm(Form $form): Form
201207
{
202208
$form = $this->adapter->getCreateForm($form, $this->currentColumn);
203209

204-
return $form->model($this->adapter->baseQuery->getModel())->statePath('recordData');
210+
return $form->model($this->adapter->baseQuery->getModel())->statePath('createRecordData');
205211
}
206212

207213
/**
@@ -211,7 +217,7 @@ public function editRecordForm(Form $form): Form
211217
{
212218
$form = $this->adapter->getEditForm($form);
213219

214-
return $form->model($this->adapter->baseQuery->getModel())->statePath('recordData');
220+
return $form->model($this->adapter->baseQuery->getModel())->statePath('editRecordData');
215221
}
216222

217223
/**
@@ -319,14 +325,14 @@ public function updateRecordsOrderAndColumn($columnId, $cardIds): bool
319325
public function openCreateForm(string $columnId): void
320326
{
321327
$this->currentColumn = $columnId;
322-
$this->recordData = [];
328+
$this->createRecordData = [];
323329

324330
// Set the base model without filling yet
325331
$this->createRecordForm->model($this->adapter->baseQuery->getModel());
326332

327333
// Pre-set the column field
328334
$columnField = $this->config->getColumnField();
329-
$this->recordData[$columnField] = $columnId;
335+
$this->createRecordData[$columnField] = $columnId;
330336
}
331337

332338
/**
@@ -351,8 +357,8 @@ public function openEditForm(string | int $recordId, string | int $columnId): vo
351357
return;
352358
}
353359

354-
// Set recordData first
355-
$this->recordData = $record->toArray();
360+
// Set editRecordData first
361+
$this->editRecordData = $record->toArray();
356362

357363
// Clear form state to avoid reactivity issues
358364
$this->editRecordForm->fill([]);
@@ -361,7 +367,7 @@ public function openEditForm(string | int $recordId, string | int $columnId): vo
361367
$this->editRecordForm->model($record);
362368

363369
// Now fill the form, which will allow nested components to initialize with the model's relationships
364-
// Using the model's data directly instead of recordData to avoid reactivity loops
370+
// Using the model's data directly instead of editRecordData to avoid reactivity loops
365371
$this->editRecordForm->fill($record->toArray());
366372
}
367373

@@ -415,7 +421,7 @@ public function createRecord(): void
415421
*/
416422
private function resetCreateForm(): void
417423
{
418-
$this->recordData = [];
424+
$this->createRecordData = [];
419425
$this->currentColumn = null;
420426

421427
// Just clear the form without chaining methods
@@ -467,7 +473,7 @@ public function updateRecord(): void
467473
*/
468474
public function resetEditForm(): void
469475
{
470-
$this->recordData = [];
476+
$this->editRecordData = [];
471477
$this->currentRecord = null;
472478

473479
// Just clear the form without chaining methods

0 commit comments

Comments
 (0)