#Scroll on validation

6 messages · Page 1 of 1 (latest)

teal frigate
#

How can i scroll to first validation error field?

gray gladeBOT
#

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

valid dirge
teal frigate
#

and where i must put this code ChesterS?

#

i try to register macro like this

public function boot(): void
{
    Component::macro('scrollOnFail', function (string $query, callable $closure) {
        try {
            $closure();
        } catch (ValidationException $e) {
            $this->dispatch('app:scroll-to', [
                'query' => $query,
            ]);

            throw $e;
        }
    });
}

and call it by

 $this->scrollOnFail('.fi-fo-field-wrp-error-message', function () {
    $this->form->getState();
});

but it doesn't workds

valid dirge
#

Sorry, this is JS code so you have to find a way to add it into the frontend. Not sure what the best way would be. Maybe a render hook?