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);
            }
        });
    }

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.
Was this page helpful?