#Can't render correctly filament form in a Livewire component

12 messages · Page 1 of 1 (latest)

molten mauve
#

Filament form rendering problems in custom Livewire component outside admin panel

final class MarkdownTextAnswer extends Component implements HasActions, HasSchemas
{
    use InteractsWithActions;
    use InteractsWithSchemas;

    #[Modelable]
    public string $content = '';

    public ?array $data = [];

    public int $questionId;

    public bool $disabled = false;

    public function mount(int $questionId, ?string $existingAnswer = null, bool $disabled = false): void
    {
        $this->questionId = $questionId;
        $this->disabled = $disabled;
        $this->content = $existingAnswer ?? '';

        $this->form->fill([
            'content' => $this->content,
        ]);
    }

    public function updated(string $property): void
    {
        // When the form data is updated, sync it back to the content property
        if ($property === 'data.content') {
            $this->content = $this->data['content'] ?? '';
        }
    }


    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                MarkdownEditor::make('content')
                    ->label('')
                    ->toolbarButtons([
                        ['bold', 'italic', 'strike', 'link'],
                        ['heading'],
                        ['blockquote', 'bulletList', 'orderedList'],
                        ['table'],
                        ['undo', 'redo'],
                    ])
                    ->disabled($this->disabled)
                    ->live(onBlur: true),
            ])
            ->statePath('data');
    }

    public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
    {
        return view('livewire.courses.quizzes.markdown-text-answer');
    }
}
// blade
<div>
    <form wire:submit="create">
        {{ $this->form }}

        <button type="submit">
            Submit
        </button>
    </form>

    <x-filament-actions::modals />
</div>
steel flameBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

minor magnet
#

If this is not inside the panel, make sure to go through the install steps of filament for the standalone components.

molten mauve
lyric fossil
#

If you’re not using the panels package, then yes.

minor magnet
molten mauve
#

It's not like version 3?

minor magnet
#

If you use components outside a panel you need to setup CSS and JS.

molten mauve
molten mauve
molten mauve
#

Actions are working. But not form.