File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -262,6 +262,38 @@ protected static function getCategoryFormComponent()
262262 'footer ' ,
263263 ])
264264 ->default ('main ' )
265+ ->suffixActions ([
266+ Forms \Components \Actions \Action::make ('fillFromExist ' )
267+ ->icon ('heroicon-o-pencil ' )
268+ ->fillForm (fn ($ state ) => [
269+ 'category ' => $ state ,
270+ ])
271+ ->form (function () {
272+ $ getCategoryOptions = function ($ search = null , $ limit = 50 ) {
273+ $ query = static ::getEloquentQuery ()
274+ ->select ('category ' )
275+ ->distinct ()
276+ ->when ($ search , function ($ query , $ search ) {
277+ $ query ->where ('category ' , 'like ' , '% ' . $ search . '% ' );
278+ })
279+ ->limit ($ limit );
280+ return $ query ->pluck ('category ' , 'category ' )->all ();
281+ };
282+ return [
283+ Forms \Components \Select::make ('category ' )
284+ ->label (__ ('inspirecms::resources/navigation.category.label ' ))
285+ ->validationAttribute (__ ('inspirecms::resources/navigation.category.validation_attribute ' ))
286+ ->options (fn () => $ getCategoryOptions ())
287+ ->searchable ()
288+ ->getSearchResultsUsing (fn ($ search ) => $ getCategoryOptions ($ search ))
289+ ->default (fn ($ record , $ get ) => $ get ('category ' ))
290+ ->required (),
291+ ];
292+ })
293+ ->action (function ($ data , $ set ) {
294+ $ set ('category ' , $ data ['category ' ]);
295+ }),
296+ ])
265297 ->live ()
266298 ->afterStateUpdated (function ($ old , $ state , $ set ) {
267299 if (trim ($ old ) !== trim ($ state )) {
You can’t perform that action at this time.
0 commit comments