Replies: 1 comment
-
Hey, I appreciate your patience with this! It is possible to set values in the changeset function. In this function you can also access the Here is some example code: def changeset(user, attrs, metadata) do
# the metadata contains the target input and assigns
target = Keyword.get(metadata, :target)
assigns = Keyword.get(metadata, :assigns)
user
|> cast(attrs, [...])
|> maybe_put_address_details(target)
...
end
# this function is being called if the input target is "place"
def maybe_put_address_details(changeset, "place" = _target) do
place_id = get_field(changeset, :place)
address_details = get_address_details(place_id)
put_change(changeset, :address_details, address_details)
end
def maybe_put_address_details(changeset, _target) do
changeset
end |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been playing around with creating a custom field that lets a user search for an address, it uses the google auto complete API to suggest matches, and when the user selects a result it auto-populates the related address fields.
Are there any existing methods available that would let me set the value of a various fields outside the normal flow?
Beta Was this translation helpful? Give feedback.
All reactions