0

In the example of title and slug inputs, which whenever something is written in title, will be written in slug.

But I want to have a checkbox that determines whether it should automatically write(convert) to slug input or not.

TextInput::make('title')
    ->reactive()
    ->afterStateUpdated(static::fillSlug(...))
    ->required(),

TextInput::make('slug')
    ->disabled(fn (callable $get) => $get('fill slug based on title'))
    ->required(),

Checkbox::make('fill slug based on title')
    ->default(true)
    ->inline(false)
    ->reactive()
    ->afterStateUpdated(static::fillSlug(...))
    ->dehydrated(false),

fillSlug sets slug if checkbox is checked

The problem:

It works on create page, but on edit page checkbox is not checked. How can I check the checkbox? I've tried ->extraAttributes(['checked' => 'true']) but that doesn't works.

amir
  • 41
  • 7

1 Answers1

0

->formatStateUsing(fn () => true) or getting the $state ->formatStateUsing(fn ($state) => !$state ? true : $state)

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 28 '23 at 08:14