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
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
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
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
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.








