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

feat: Add option to emit ionChange only on day selection in ion-datetime #27706

Closed
3 tasks done
WongSIuWing opened this issue Jun 27, 2023 · 2 comments
Closed
3 tasks done
Labels

Comments

@WongSIuWing
Copy link

WongSIuWing commented Jun 27, 2023

Prerequisites

Describe the Feature Request

I propose adding an option to the ion-datetime component that allows it to emit the ionChange event only when the user selects a day. This would make the component more practical for range selection, as it would only emit events when the user has made a complete date selection.

Describe the Use Case

It opens up the possibility to use this datetime picker for selection of a date range with the multiple attribute.

Instead of,

Currently, the ion-datetime component emits the ionChange event whenever the user changes the year, month, or day. This make it almost impossible when using the component for range selection, as it triggers unnecessary events when changing the year or month regardless whether or not, client actually want that value to be register.

Describe Preferred Solution

So inside the ion-datetime element, add a property that based on 3 types of string, day/month/year (I suggest day would be the most heavy use case so it could be a boolean as well).

Then maybe in ionic library, in the logic that will automatically emits a new value, when changing year or month. Use an if case to read this value, then early return to quit the logic that automatically emits a new value.

Describe Alternatives

An alternative solution could be to implement custom logic to revert the value when the user changes the year or month and only allow the ionChange event to be emitted when the user selects a day.

Yet this approach caused bug and confusion when user actually select the date range with the same day but different year as this legit action from user will be catergorized as ionic automatic emits instead in this alternative approach.

Hence this approach may be more complex and less intuitive for developers.

Related Code

<ion-datetime [onChange-only]="day" [multiple="true"]></ion-datetime>

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Jun 27, 2023
@liamdebeasi liamdebeasi self-assigned this Jun 27, 2023
@liamdebeasi
Copy link
Contributor

Thanks for the report. The use case provided is for date range selection, so I am going to merge this with #23572. I think it would be best to implement proper date range selection so developers do not need to implement it themselves.

@liamdebeasi liamdebeasi closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
@liamdebeasi liamdebeasi removed their assignment Jun 27, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Jul 27, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jul 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants