Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jj63systems's avatar

HELP! Understanding filament form - why doesn't my data show?

Hi there, my filament form doesn't show any data in the fields (even if I hard-code a default value) - here's the story.

I have a custom page and have coded an action button. It is invoked like this

                {{ $this->slideAction()->record(\App\Models\ArchObject::find($result->id)) }}
                @endif

My slideAction function is (note I have hard-coded an ID)

    public function slideAction(): Action
    {
        return Action::make('slide')
            ->slideOver()
            ->mountUsing(function (Action $action, $record) {
                // Set the form schema dynamically based on the record
                $action->form(
                    ArchObjectResource::getFormSchema(\App\Models\ArchObject::find(193458))
                    
                );
                
            })
            ->action(function (array $data, ArchObject $record) {
                // Handle form submission here
            });
    }

Within ArchObjectResource::getFormSchema we have

   public static function getFormSchema(?ArchObject $record = null): array
    {

        return [
            Forms\Components\TextInput::make('object_key')
            // ->default($record?->object_key)
            ->default('hello')
            ->required(),
            Forms\Components\TextInput::make('hcat_reference')
                ->default($record?->hcat_reference)
                ->required(),
...
...

I can dd($record) here and see I have the complete record and I can dd($record->object_key) and see the expected value there. But they don't appear in the form fields.

I'm sure it's something simple - but what?

thanks, optimistically, j

0 likes
6 replies
LaryAI's avatar
Level 58

It looks like you're trying to dynamically populate a form in a Filament action slide-over, but the default values aren't appearing in the form fields. This issue often arises from how the form schema is being set up or how the data is being passed to the form.

Here are a few things to check and try:

  1. Ensure the Record is Passed Correctly: Make sure that the record is being passed correctly to the getFormSchema method. You seem to be doing this correctly, but double-check that the record is not null when you call getFormSchema.

  2. Check the Form Schema: Ensure that the form schema is correctly using the record to set default values. You commented out the default value for object_key. Uncomment it and ensure it's correctly accessing the record's properties.

    public static function getFormSchema(?ArchObject $record = null): array
    {
        return [
            Forms\Components\TextInput::make('object_key')
                ->default($record ? $record->object_key : 'default_value')
                ->required(),
            Forms\Components\TextInput::make('hcat_reference')
                ->default($record ? $record->hcat_reference : 'default_value')
                ->required(),
            // Add other fields as necessary
        ];
    }
    
  3. Check the Action Setup: Ensure that the mountUsing method is correctly setting the form schema. You might want to log or dd the $record inside the mountUsing closure to ensure it's being passed correctly.

    public function slideAction(): Action
    {
        return Action::make('slide')
            ->slideOver()
            ->mountUsing(function (Action $action, $record) {
                // Debugging: Check if the record is being passed correctly
                // dd($record);
    
                $action->form(
                    ArchObjectResource::getFormSchema($record)
                );
            })
            ->action(function (array $data, ArchObject $record) {
                // Handle form submission here
            });
    }
    
  4. Check for JavaScript Errors: Sometimes, JavaScript errors can prevent the form from rendering correctly. Open your browser's developer tools and check the console for any errors.

  5. Clear Cache: If you've made changes and they don't seem to be taking effect, try clearing your application's cache. Run the following commands:

    php artisan cache:clear
    php artisan config:clear
    php artisan view:clear
    
  6. Verify Filament Version: Ensure that you are using a compatible version of Filament with your code. Sometimes, breaking changes in newer versions can cause unexpected behavior.

By following these steps, you should be able to identify why the form fields aren't displaying the expected data. If the issue persists, consider providing more context or checking the Filament documentation for any updates or changes that might affect your implementation.

jj63systems's avatar

I reworked the code so the blade now says

<button wire:click="mountAction('slide', { record: {{$result->id}} })">

and the slideAction is

    public function slideAction(): Action
    {
        return Action::make('slide')
            ->slideOver()
            ->form(
                // ArchObjectResource::getFormSchema($record)
                ArchObjectResource::getFormSchema(\App\Models\ArchObject::find(193458))

            )


            ->action(function (array $data, ArchObject $record) {
                // Handle form submission here
            });
    }

Note use still of hard-coded id - but this structure does work in that, now, the ArchObject record is being rendered in the form component.

My question is though how do I access the $result->id value within slideAction so that I can pass it into getFormSchema?

jj63systems's avatar

@jaseofspades88 Thanks for the link, interesting and useful overview. However my issue is no longer with having a blank form presented per se, it's simply a need to understand where, when using Actions, the blade data (in this case the $id from <button wire:click="mountAction('slide', { record: {{$result->id}} })"> can be accessed within the function slideAction()

Can you help?

thanks j

jaseofspades88's avatar

Ask yourself what problem you're trying to fix, @jj63systems. I've never once needed to access the blade for actions in Filament. I don't imagine there's anything you're doing with actions that can't be done in a more pragmatic way.

jj63systems's avatar

@jaseofspades88 Apologies for the late response, been on hols. My issues are resolved through a bit more learning / understanding the interactions between php & laravel & browser. Persistence pays off :)

Always grateful for comments / advice.

thx j

Please or to participate in this conversation.