amos-kibet

amos-kibet

Ecto changeset validations cause lag in displaying nested form fields

I have a form that I use to add users to an organization, that looks like this:

The problem:
Clicking on the Add User button takes a few milliseconds (~500ms) before the input fields are displayed, and the delay compounds as I add more users. Note that clicking that button sends a validate event to the server.
Checking the server logs, validation happens for all of the already filled fields. I’m not sure if that’s expected, or I’m doing something wrong in the code. It feels redundant to re-validate all the fields; I expect validation to happen only for the field in focus, but maybe it’s how inputs_for/1 works.

This is my changeset function:

 def invite_changeset(organization, attrs) do
    organization
    |> cast(attrs, [])
    |> cast_assoc(:users,
      with: &User.invitation_changeset/2,
      sort_param: :users_sort,
      drop_param: :users_drop
    )
  end

What I have tried so far:
I am preloading :users that cast_assoc/3 is using. I have tried not running validations untill the form is submitted, but that doesn’t work with inputs_for/1; the form is not being rendered when I click on Add User button on the UI. Also tried providing a changeset that has no validations (just casting) when validating, but the delay is still there, even though cast_assoc/3 does no validation, just casting the params.

The question:
Honestly, I am not entirely sure what the cause of the delay is, but I suspect it is the changeset validation. How can I fix this delay?

Marked As Solved

amos-kibet

amos-kibet

Turns out the delay was being caused by a password hashing step, done by Bcrypt. Skipping it during form validation, and only running it during form submission solved the issue.

Also Liked

LostKobrakai

LostKobrakai

That’s how changesets work. They compare the base state with the complete set of changes in the form. There is no partial validation as changesets do not support any partial delivery of changes nor revalidation (as in removing errors) of already validated fields.

Additionally inputs_for is not granularly change tracked like individual root level inputs. This is a known limitation of how inputs_for is implemented.

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
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
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New

Other popular topics Top

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 41539 114
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement