© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•11mo ago•
3 replies
valentin_morice

Plugin development - Filament Json Column

Hi, currently working on a new version for a Filament plugin. I want to stop form submission if the state provided is improper. The plugin is a JSON viewer/editor, so I'm trying to parse the state. Here's the code.
protected function setUp(): void
    {
        parent::setUp();

        $this->beforeStateDehydrated(function(FilamentJsonColumn $component, $state) {
            if (is_string($state)) {
                $decodedState = json_decode($state, true);

                if (json_last_error() !== JSON_ERROR_NONE) {
                    Notification::make()
                        ->title($component->getErrorMessage() === '' ? 'Fix the invalid JSON values' : $component->getErrorMessage())
                        ->danger()
                        ->send();

                    throw ValidationException::withMessages([]);
                }

                $component->state($decodedState);
            }
        });
    }
protected function setUp(): void
    {
        parent::setUp();

        $this->beforeStateDehydrated(function(FilamentJsonColumn $component, $state) {
            if (is_string($state)) {
                $decodedState = json_decode($state, true);

                if (json_last_error() !== JSON_ERROR_NONE) {
                    Notification::make()
                        ->title($component->getErrorMessage() === '' ? 'Fix the invalid JSON values' : $component->getErrorMessage())
                        ->danger()
                        ->send();

                    throw ValidationException::withMessages([]);
                }

                $component->state($decodedState);
            }
        });
    }

I'm doing the validation before dehydrating the state, but it feels like a dirty hack, and it's causing issues with dynamic classes in Alpine for a reason I can't seem to understand. Is there a better way to do that, by defining validation rules by default from inside the plugin?

EDIT: Managed to solve the Alpine class binding issue, but would still appreciate if there's another supported way to do validation from inside the component.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Filament json column
FilamentFFilament / ❓┊help
2y ago
Filament GrapesJS - Plugin Development
FilamentFFilament / ❓┊help
3y ago
Query JSON columns in filament tables
FilamentFFilament / ❓┊help
3y ago
Custom Column Filament
FilamentFFilament / ❓┊help
3y ago