-
Notifications
You must be signed in to change notification settings - Fork 1
Yield a friendly error if user tries to submit a one time allocation that is higher than the allowable total giving amount #128
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Controller } from "@hotwired/stimulus" | ||
|
|
||
| const currency = new Intl.NumberFormat("en-US", { | ||
| style: "currency", | ||
| currency: "USD", | ||
| maximumFractionDigits: 0, | ||
| }) | ||
|
|
||
| // Keeps a one-time giving amount within the scenario's remaining giving budget. | ||
| // Sets a custom-validity message so the browser blocks submission (via native | ||
| // constraint validation, regardless of number-input support) and shows a | ||
| // friendly error without closing the modal. | ||
| export default class extends Controller { | ||
| static values = { max: Number } | ||
|
|
||
| connect() { | ||
| this.element.addEventListener("input", this.validate) | ||
| this.validate() | ||
| } | ||
|
|
||
| disconnect() { | ||
| this.element.removeEventListener("input", this.validate) | ||
| } | ||
|
|
||
| validate = () => { | ||
| const overMaxValue = this.element.value !== "" && Number(this.element.value) > this.maxValue | ||
| this.element.setCustomValidity(overMaxValue ? this.message : "") | ||
| } | ||
|
|
||
| get message() { | ||
| return `Enter an amount of ${currency.format(this.maxValue)} or less — that's your remaining one-time giving budget.` | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are asserting this context in the tests, so we may be good to remove these comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I noticed when working with AI agents is that they do pay attention to these breadcrumbs, so lately I've been kind of leaving them in there...provided that they update these when they change this logic. But I can remove this for now.