Fixed calendar switch a month with the latest enabled dates #187
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.
Closes #157
New test has been added #186
I tried to fully fix the problem with auto-switching to the latest selected dates, but I cannot achieve this due to this behavior in the ion-datetime https://ionicframework.com/docs/api/datetime#setting-values-asynchronously:
As you can read, datetime automatically jump to the selected date, so I decided to fix at least the most annoying problem
Let's imagine that we selected the following dates in the Edit mode:


Let's click on


Save
and we should see something like that:But when we click on
Edit
again our date will be automatically switched at the begin of the latest active datesI was able to fix that by tricking ion-datetime. For this I called
Array
'sreverse
function on thelastPeriodDays
array and pass it asvalue
prop to the ion datetime. In this case ion-datetime jumps to the month in which we have the last day of range, believing that this is the beginning of the range, but in fact this is the end of the rangeWith this fix, the situation described above will looks like this:


Click on
Edit
:On the other side, this hack still not fix the following behavior and I don't think that we can do that without ion datetime's code modifications



Selected dates:
Click on
Save
:Click on
Edit
again:But, in my opinion, this behavior is more obvious and logical, because in any case the ion datetime is jump to the last month, where the last selected day is located