Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting value from changeset to display number only in input #215

Open
SamuelMTDavies opened this issue Jan 30, 2024 · 2 comments
Open

Comments

@SamuelMTDavies
Copy link

I have an issue where a user inputs a value into a numerical input. If an issue occurs further down the call chain and the changeset is not valid the numerical input then displays the value with the currency symbol.

Is there a way to extract and display the value only?

<.input field={f[:amount]} type="donation" required />

Input before changeset:
Screenshot 2024-01-30 at 14 05 06

Input if another input causes invalid changeset and page is re-rendered:

Screenshot 2024-01-30 at 14 05 20

How do I ensure the amount is extracted from the changeset when this happens? Because this way if the form was submitted again would then cause an error on the amount input now because of the symbol.

@lessless
Copy link

@maxgronlund
Copy link

I tried https://elixirforum.com/t/edit-and-update-using-elixir-money-library/25218/11 and fixed an bug when the value is a changeset with a validation error.

At the end I'm keeping running to this catch. If I don't convert money to decimal the input form shows nothing.
If I do convert money to decimal as proposed in the example above it looks right,
But if I change any other fields more than one time the value starts to raise by a factor 100 each time.
I have tried a lot of hacks, but I prefere to keep my code clean so until I understand this better I will omit Money

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants