Add improved day validation workaround for leap year date input bug#695
Open
dagjomar wants to merge 1 commit into
Open
Add improved day validation workaround for leap year date input bug#695dagjomar wants to merge 1 commit into
dagjomar wants to merge 1 commit into
Conversation
Fixes: wojtekmaj#659 There is an issue when trying to input a date such as "29 / 02 / 2024" (February 29th 2024) which is a leap year and should be valid. The validation runs into a state where the input fields are first rendered with the inputs day: 29 month: 2 year: 202 which is not a leap year, and thus the day 29 is not valid for this state. The problem occurs when running the onChangeExternal, which tries to read the validity state of the dayInput react Ref. However, that ref has last been rendered with a min/max number value calculated from the previous month and year (month 2 and year 202). Therefore the day input field still believes that the day 29 is not valid, even though we have just entered 2024 into the year field. This workaround is to just use a new instance of a DOM input field that emulates what the real input field should do, and check this validity value instead, which will be correct using the current updated values. The real input field values will become valid next render cycle. Ironic to make another "shadow DOM" inside react, but at least it works. Added a bunch of unit tests for this case, and improved the test coverage of utility methods as well
2 tasks
2 tasks
9e78bbc to
06772d8
Compare
4e7cb80 to
4575a91
Compare
|
@wojtekmaj Are there any plans to merge this? |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: #659
There is an issue when trying to input a date such as "29 / 02 / 2024" (February 29th 2024) which is a leap year and should be valid.
The validation runs into a state where the input fields are first rendered with the inputs
day: 29
month: 2
year: 202
which is not a leap year, and thus the day 29 is not valid for this state.
The problem occurs when running the onChangeExternal, which tries to read the validity state of the dayInput react Ref. However, that ref has last been rendered with a min/max number value calculated from the previous month and year (month 2 and year 202). Therefore the day input field still believes that the day 29 is not valid, even though we have just entered 2024 into the year field.
This workaround is to just use a new instance of a DOM input field that emulates what the real input field should do,
and check this validity value instead, which will be correct using the current updated values. The real input field values will become valid next render cycle. Ironic to make another "shadow DOM" inside react, but at least it works.
Added a bunch of unit tests for this case, and improved the test coverage of utility methods as well