⌘K
Noting Found

View all related articles

Scroll back to the form errors using alpineJS

Snippets 1 min read

Caleb the creator of AlpineJS, and Livewire. Shared a post recently, on twitter showing how to Scroll back to the error message in the form.

Making this feature, will improve Your UX, and help your users, use your websites better.

Here's the example, using laravel blade:

1@error('state.field')
2 <p class="text-sm text-red-400"
3 x-init="$el.closest('form').scrollIntoView()">
4 {{ $message }}
5 </p>
6@enderror

If you have errors in the bottom of the form page, you can do this:

1@error('state.field')
2 <p class="text-sm text-red-400"
3 x-init="$el.closest('form').querySelector('[aria-invalid=\'true\']').closest('label').scrollIntoView()">
4 {{ $message }}
5 </p>
6@enderror

PS: You can use this feature in any form, once you have alpineJs installed.

Related Tags

About the Author

Oussama's Profile Picture
Oussama
Full Stack Web Developer | Technical Writer

Oussama is an experienced full-stack web developer with a strong focus on Laravel. He's passionate about crafting web applications with Filament and the TALL Stack. With 8+ years of experience, and he's a dedicated open-source contributor.

Comments

Join our newsletter

Subscribe to Our Newsletter and never miss our offers, latest news, Articles, etc.

We care about the protection of your data. Read our Privacy Policy.