© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
6 replies
Raj Siva-Rajah

Clean way to avoid escaping of quotes in JS in extraAttributes

Hi all

I'm using
HtmlString
HtmlString
when using JS in
extraAttributes()
extraAttributes()
but it's adding slashes before all single and double quotes. The only way I've been able to avoid that is by using
Illuminate\Support\Js
Illuminate\Support\Js
:

->extraAttributes([
   'x-on:click' => new HtmlString('$el.classList.add(' . Js::from('pointer-events-none') . ',' . Js::from('opacity-70') . ')'),
]);
->extraAttributes([
   'x-on:click' => new HtmlString('$el.classList.add(' . Js::from('pointer-events-none') . ',' . Js::from('opacity-70') . ')'),
]);


Which isn't very readable... Is there a cleaner of doing this?
Solution
->extraAttributes(['x-on:click' => new HtmlString('$el.classList.add(\'pointer-events-none\', \'opacity-70\')')])
->extraAttributes(['x-on:click' => new HtmlString('$el.classList.add(\'pointer-events-none\', \'opacity-70\')')])


?
Jump to solution
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

Prevent extraAttributes escaping
FilamentFFilament / ❓┊help
2y ago
extraAttributes in v3
FilamentFFilament / ❓┊help
2y ago
where to search extraAttributes() ?
FilamentFFilament / ❓┊help
3y ago