tmbb

tmbb

LiveView phx-no-feedback without tailwind

I want to create CoreComponents based on Bootstrap 5 instead of tailwind. I’m having issues with form validation. It seems like the only way Phoenix has of telling the client that feedback should be shown or not on a given form field is through the phx-no-feedback class. Apparently, tailwindcss does some kind of dark magic with class pseudoselectors (?) in which things work (or maybe it’s the subset of tailwind used by Phoenix? I don’t know much about tailwind and my bootstrap client adventures are mainly a way of avoiding having to learn about tailwind and the respective build tools).

With tailwind, one does something like phx-no-feedback:some-tailwind-utility-class, but that only works due to tailding JS and CSS magic, right?

If I am to use Bootstrap 5, what is the right way to add the is-valid and is-invalid bootstrap classes to my input components to mimic the behaviour of the default CoreComponents file? I’m not very knowledgeable about CSS but I’m willing to learn enough to make it work if anyone can point me to the right sources. I believe there is probably a way of doing this that doesn’t depend on taiwlind and doesn’t require rewriting the original bootstrap CSS file to make it work.

Marked As Solved

LostKobrakai

LostKobrakai

All the dark magic of tailwind does is apply certain styles only if the phx-no-feedback class is present or not present.

So phx-no-feedback:border-zinc-300 becomes

.phx-no-feedback.border-zinc-300 { border-color: …; }

Given how component frameworks like bootstrap work you cannot easily make their is-valid/is-invalid class be scoped to the existance of another class. You’d either need to copy their class and add the necessary scoping or use some JS to react to phoenix adding or removing the phx-no-feedback class.

Also Liked

andrejsm

andrejsm

Just encountered the same issue with combining Bootstrap with Live View. If SASS is involved, there is a workaround by extending the .is-invalid class:

:not(.phx-no-feedback) > .has-error {
    @extend .is-invalid;
}

Then apply newly created .has-error instead of .is-invalid.

LostKobrakai

LostKobrakai

It’s client side. That‘s the whole reason for this being done with a class: It doesn‘t require interaction with the server. If you focus, but not change an input any errors will show up on blur.

josevalim

josevalim

Creator of Elixir

We did Bootstrap 4 with LV quite some time ago. Some of the lessons may still apply: Using Bootstrap Native with Phoenix LiveView - Dashbit Blog - the code was also open sourced on the bytepack repo in our org.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement