Skip to content

Commit f136423

Browse files
committed
convert display order on document type form (title <-> name)
1 parent 3ff6042 commit f136423

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/Filament/Resources/DocumentTypeResource.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public static function getBaseFormSchema($operation = 'create'): array
7474
->columns(1)
7575
->aside()
7676
->schema([
77-
static::getSlugFormComponent()->inlineLabel(),
7877
static::getTitleFormComponent()->inlineLabel(),
78+
static::getSlugFormComponent()->inlineLabel(),
7979
static::getShowAsTableFormComponent(),
8080
static::getCategoryFormComponent()->inlineLabel(),
8181
static::getIconFormComponent()->inlineLabel(),
@@ -274,7 +274,14 @@ protected static function getTitleFormComponent()
274274
return Forms\Components\TextInput::make('title')
275275
->label(__('inspirecms::resources/document-type.title.label'))
276276
->validationAttribute(__('inspirecms::resources/document-type.title.category'))
277-
->required();
277+
->required()
278+
->live(true, 5000)
279+
->afterStateUpdated(function ($component, $state, Forms\Get $get, Forms\Set $set, $operation) {
280+
// Fill slug if empty / operation is create
281+
if ($operation === 'create' || empty($get('slug'))) {
282+
$set('slug', Str::slug($state));
283+
}
284+
});
278285
}
279286

280287
/**
@@ -285,17 +292,13 @@ protected static function getSlugFormComponent()
285292
return Forms\Components\TextInput::make('slug')
286293
->label(__('inspirecms::resources/document-type.slug.label'))
287294
->validationAttribute(__('inspirecms::resources/document-type.slug.category'))
288-
->live(true, 300)
289-
->afterStateUpdated(function ($component, $state, Forms\Get $get, Forms\Set $set, $operation) {
290-
$component->state(Str::slug($state));
291-
// Fill slug if empty / operation is create
292-
if ($operation === 'create' || empty($get('title'))) {
293-
$set('title', $state);
294-
}
295-
})
296295
->unique(table: static::getModel(), column: 'slug', ignoreRecord: true)
297296
->autofocus()
298-
->required();
297+
->required()
298+
->live(true, 5000)
299+
->afterStateUpdated(function ($component, $state) {
300+
return $component->state(Str::slug($state));
301+
});
299302
}
300303

301304
/**

0 commit comments

Comments
 (0)