sodapopcan

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 :upside_down_face:

Anyway, just wondering if anyone has thought about or dealt with this.

Showing Posts 1 to 10

nmk

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

sodapopcan OP

It is not as they are often ignored.

There are hacks you can do like generating “junk” name input 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

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&#8_204;treet Add&#8_204;ress

A 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

sodapopcan OP

Interesting! We’ll test this out (accessibility is important to us so we’ll see). Thanks!

DaAnalyst

DaAnalyst

I’m not sure I understand what problem you have there. Been implementing forms in LV without any autocomplete issues (as inautocomplete="off").

Also, I don’t get the problem you have with hidden fields.

sodapopcan

sodapopcan OP

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 name attributes. This isn’t possible (or not easy) in LiveView. Even outside of LiveView it’s not ideal.

DaAnalyst

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:

  1. copying/syncing those values from dummy fields to hidden fields
  2. validating server-side the hidden fields while showing the errors in the feedback for dummy fields

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 model used 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

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

sodapopcan OP

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 readonly and 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!

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews