im3000
Hello!
I am stuck figuring out how to set a custom CSS classes for text inputs in Surface. Basically, I would like to add a red border for the invalid text field. I can probably use class={invalid: @field_status}, but I am wondering if there is somehow a way to make this apply for all fields by creating some kind of helper or wrapper. For the reference, I am using Ecto and there are changesets involved for the forms in question.
Any help, pointers, links are much appreciated. Thank you!
Trending in Questions
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
Hi all!
I know that quite a few people use Phoenix LiveView but it is hard to get a more up-to-date list of folks/companies using it. I ...
New
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hi everyone :waving_hand:
I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #ai
- #authentication
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-eu
- #distillery
- #security
- #processes
- #api
- #forms
- #hex











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Malian
Hi @im3000 !
Thanks for using Surface!
If the ErrorTag does not fit your needs, you could indeed dynamically add a class to the
TextInputcomponent with theclassprop like you mentioned.There is no currently no way to dynamically add a class to a component across the application. A solution could be to create your own
TextInputcomponent that is a wrapper for the Surface one, or that delegates the rendering to Phoenix (it is basically what the Surface component does). In that component, you can retrieve the form context and do what you want with it.Take a look at
https://github.com/surface-ui/surface/blob/master/lib/surface/components/form/text_input.ex, I am sure you will find what you need there.That being said, I am curious how you imagine a “dynamically” class for one component could work? Could you explain us how you imagine the API? It will help us to evaluate the way of implementing this to Surface.
im3000
Thank you for the answer @Malian!
As you suggested, I could probably get away with a derived input component. What I had in mind was a tighter coupling to Ecto changesets, but that coupling might be too tight. On the other hand all the information is already probably there.
The idea sparked after reading Dynamic forms with Phoenix « Plataformatec Blog post and especially the “Customizing Inputs” section. I am thinking if Surface has an
Fieldtag that acts as a wrapper for inputs and error tags it might be quite easy to add an error CSS class to the inputs that the field is wrapping. With that said, I haven’t looked at the Surface’s code too close yet so take my thoughts with a pinch of salt.What do you think? Is it doable or is it not in line with Surface’s design philosophy?
harmon25
Very doable - but not a native surface concern.
Phoenix does a bit of magic to hide errors on fields the user has not yet interacted with.
This ‘magic’ is done with these classes when using
ErrorTag:Obviously
display:none;would not work on a border - and this will have to be modified achieve applying anerrorborder to a field.Think you would apply a default border if
.phx-no-feedbackis present, and when just.invalid-feedbackis present on the field, apply theerrorborder or similar…Could also use more intelligent CSS selectors like if
.invalid-feedbackis present on a parent node - to apply certain styles…Malian
@harmon25 correct me if I am wrong, but Phoenix add
phx-no-feedbackfrom theerror_tagfunction in yourErrorHelpersmodule. Does Phoenix addphx-no-feedbackoninputsas well?harmon25
No phoenix does not do that for you, the dom node needs an accurate
phx_feedback_forattribute - Form bindings — Phoenix LiveView v0.15.7 (hexdocs.pm) to apply thephx-no-feedbackclass.So a special styles like:
would be required to pull this off, as
display: none;is not really an option for the input itselfim3000
I am a bit confused. If Surface could add some kind of css class to the
<form>or<div>(Field) element in case of field error it would be no problem doing a little CSS-fu to style the inputs in question. Right now the generated DOM node forErrorTaghangs on its own and there is no easy way to find its input without doing some JS-fu.Right now I’ve solved it with a hack adopted from the article mentioned higher up, but I feel there must be a better way.
And I put this helper func in my LiveHelpers module that I then imported in my Surface component.
TBH I feel like that meme science dog atm .. hehe. Still learning! But something tells me that this could somehow be solved in the Surface lib itself. Either by Surface configuration or maybe in some kind of a separate helper module.