`AshPhoenix.Form` not applying changes
I am using forms as below:
And the action
:new_account
is as follows:
I would expect on submit that my change is hashing the secret however it isn't and the change is running when the form is created. The change is also below
Any ideas?18 Replies
I’m not sure why this wouldnt run on create, but the way that changes work is that they run when the changeset is validated, which happens on every form change. If you want to push something off to the action, in your change you do something like
You should use before action hooks for anything intensive, anything that hits a database for example, and for anything you want to happen exactly once.
I'm not sure why it isn't but it is inserting the passwords in plain text
I suspect its something in your
with
block falling through:
Yeah looks like it is
as it executes 3 times
If you wrap it in
before_action/1
it will work the way you expect 🙂 But I'd also advise using different keys to avoid this potential problem in the future.
Or alternatively don't have a fallthrough clauseit looks like this now,
That looks right to me 🙂
the secret is coming out as
nil
I figured it out🥳
I had the wrong changeset key lol
that was the issue all along ðŸ˜
😆
Still a good lesson to learn about
before_action/2
Yeah
Because imagine if you had a change that created a related thing in a database somewhere
if you didn't wrap it in
before_action/2
you'd create one for every keystroke they did on the form 😆😆
That reminds me of another issue I had, let me make a new forum thread
As the first user of our new support forums stuff, can you tell me if its possible for you to close this post? Right click on it in the sidebar and select "close". That may be something that only administrators can do.
The person who made it can close it, so yeah I can
Nice. I wonder if we should also add a
solved
tag ...Could be nice for people searching? With a little green tick 🤣