Skip to content

Commit f7b52da

Browse files
committed
Only update slug when it has not been changed
1 parent c615e25 commit f7b52da

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/Fields/Repeater.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,15 @@ public function getForm(): array
159159
->required()
160160
->placeholder(__('Name'))
161161
->live(debounce: 250)
162-
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
162+
->afterStateUpdated(function (Set $set, Get $get, ?string $state, ?string $old) {
163+
$currentSlug = $get('slug');
164+
165+
if (! $currentSlug || $currentSlug === Str::slug($old)) {
166+
$set('slug', Str::slug($state));
167+
}
168+
}),
163169
TextInput::make('slug')
164-
->readonly(),
170+
->required(),
165171
Select::make('field_type')
166172
->searchable()
167173
->preload()
@@ -219,4 +225,4 @@ private static function generateSchemaFromChildren(Collection $children): array
219225

220226
return $schema;
221227
}
222-
}
228+
}

src/Filament/RelationManagers/FieldsRelationManager.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ public function form(Form $form): Form
4343
->required()
4444
->placeholder(__('Name'))
4545
->live(debounce: 250)
46-
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
46+
->afterStateUpdated(function (Set $set, Get $get, ?string $state, ?string $old) {
47+
$currentSlug = $get('slug');
48+
49+
if (! $currentSlug || $currentSlug === Str::slug($old)) {
50+
$set('slug', Str::slug($state));
51+
}
52+
}),
4753

4854
TextInput::make('slug')
49-
->readonly(),
55+
->required(),
5056

5157
Select::make('field_type')
5258
->searchable()
@@ -214,4 +220,4 @@ public static function getPluralModelLabel(): string
214220
{
215221
return __('Fields');
216222
}
217-
}
223+
}

0 commit comments

Comments
 (0)