sodapopcan
Does anyone have any experience mangling browser autocompletion with LiveView? I know this is a general very frustrating topic, but the LiveView programming model makes it a bit hard to implement the regular solutions of hidden inputs (visually breaks validation as well as LiveViewTest), generating garbage input names (names need to match the Ecto schema, would require some very nasty hackery) and general vanilla JS solutions are hard without phx-ignoreing the whole form (why even use LV at this point?).
My mind is currently at creating a macro that will create two different versions of every schema, one normal and one with deterministically generated field names and switch between them just before reading and just before persisting. This is pretty insane (not to mention awful for debugging) so I likely won’t do this ![]()
Anyway, just wondering if anyone has thought about or dealt with this.
Trending in Questions
Other Trending Topics
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
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
nmk
Could you elaborate on what the desired behaviour of such a “mangled” field would be?
Disabling autofill/autocomplete on all or certain form fields is not sufficient?
sodapopcan
It is not as they are often ignored.
There are hacks you can do like generating “junk”
nameinput attributes, (<input name={generate_field(:name)} value={...} />) but of course this isn’t going to cut with LiveView without doing a whole bunch of trickery.dblack
Yes, I’ve had this problem with Chrome based browsers ignoring autocomplete for address fields.
I jammed in non printing characters into the label (remove the underscores)
S_204;treet Add_204;ressA hack yes, but i couldn’t find another way at the time and haven’t revisited it. I didn’t need to do anything with the name attributes.
This worked for my scenario, I’m not sure what it will do for screen readers (my scenario is for a small in house app where screen readers were not a requirement).
sodapopcan
Interesting! We’ll test this out (accessibility is important to us so we’ll see). Thanks!
DaAnalyst
I’m not sure I understand what problem you have there. Been implementing forms in LV without any autocomplete issues (as in
autocomplete="off").Also, I don’t get the problem you have with hidden fields.
sodapopcan
I think third party fillers are the culprit, but I’m also not sure. It’s certainly not just an us-problem as there is a bunch of info on it out there. Our problem is that in user testing a non-tech-savvy user was using some kind of auto-completer (we’re trying to find out which one) and it filled in a required field they’d scrolled past and was off screen! In any event, our app is of the nature that form auto-completion never makes sense. Users are always adding completely different data and we’d rather just disable auto-completion across the board to avoid confusion. Case in point: it took us quite a while to realize what had happened with that user (we had a recording but again it got filled off-screen) as we first assumed it was a bug on our side.
Also, the “hidden field” thing is just a technique for doing this where you have the real fields as hidden fields and the visible ones as junk
nameattributes. This isn’t possible (or not easy) in LiveView. Even outside of LiveView it’s not ideal.sodapopcan
More context: https://stackoverflow.com/questions/2530/how-do-you-disable-browser-autocomplete-on-web-form-field-input-tags
DaAnalyst
By filled off-screen you mean the field was not visible to the user while they were filling it because it was scrolled out of the viewport or something or because you placed it in a deemed-invisible part of the screen so you can fill it programmatically?
Anyway, filling hidden fields with values typed into junk fields would require having something like two forms (of fields) where the one with hidden fields gets submitted while the one with the dummy (but real looking) ones does not.
Your problem here is two fold:
You can do this in LiveView, but you’ll either need a JS framework for #1 or write the input field event listeners in a hook yourself. Personally, I still use AlpineJS. I have it locked at v3.10.3 before it went completely incompatible with LV streams in v3.12.x+. Supposedly, you can also use Petite Vue which supposedly has most of Alpine features, including
modelused for input fields.As for #2, it’s simple. LV supports (used to support? - I’m still on
phx-feedback-for) providing a different field for feedback, so you can have your dummy fields use your hidden fields’ feedback.garrison
I wasn’t familiar with this problem either. This MDN page is a good overview.
The “magic” of form handling in Phoenix definitely makes this annoying to deal with.
sodapopcan
I think might be misunderstanding. I was just providing some “classic solutions” that I’d rather not use because they are all too complex with LiveView (and sorta terrible in general). But I also I missed providing some context. So it’s this:
The user neglected to fill in a required field, then kept scrolling until the field was off-screen. They part I wasn’t clear about is that they were using and auto-filler that fills in fields they aren’t even focused on as they go. So it ended up filling in the required field they’d missed with some junk it thought it was correct. When the user hit save the forum successfully submitted then presented them with data they were surprised to see.
My CTO found an interesting potential solution I have yet to tried but will later today and can report back. In a nutshell, you make all fields
readonlyand toggle that attribute on focus/blur. If it works, this would play really nicely with LV since it can be done with JS commands.I appreciate the response, though!