-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Allow DateTime to have a starting date without setting the object's value #9846
Comments
@mikewagz I had a half-written feature request that is similar, so I'll piggyback on yours. DateTime needs a "presentWith" input property which is what the dials in the interface will be set to when a user opens the control, but before they've selected a date and put data in the model. It could be bound to a date in your code: You could pass in something that matches your displayFormat (or pickerFormat if that makes more sense): If you've set min or max properties, you could use those strings for convenience:
|
So just some comment on this As for a While it's an inline control, it's default value and presented value is the current date. So if I toggled the alarm and hit save, it would just take that fine. I see no issue with the "presented value" being the actual value of the dateTime. |
The iOS alarm is too simple to compare to other use cases:
But if you have a more complicated form (several other inputs, start and end dates, follow up screens that depend on those dates, etc.), and you put valid presets in the model:
Starting the form with preset DateTime values is like putting John and Doe in the model as first and last names, and counting on the user to change them while writing extra code to respond if they don't. A In fact, |
@mhartington - I belive a valid use case for this involves forms where a date field is optional. I don't want to set a value to the field, as the user may desire to leave it blank. However, if they choose to enter a date, there should be an option to start it at a certain value instead of the maximum date allowable by the field (which is the current default.) A concrete example would be "follow_up_date". A user may or may not want to input something in here. If they do, the presented date when they open the DateTime UI should be tomorrow, not 12-31-2025. Currently this user experience involves the user scrolling all three date fields quite a bit to get from, say, 12-31-2025 to 1-6-2017. Let me know if that makes sense. Thank you and thanks for creating such a great framework for building mobile apps! |
Both comments make sense. We will revisit this post 2.0 final release. |
Time to revisit, I guess |
+1 This is a VERY common use case that I encounter often. |
My issue was closed as part-duplicate: #10710 But it has different details so I copy-paste my post here. Ionic version: (check one with "x") I'm submitting a ... (check one with "x") Current behavior: If
If I scroll the year to 2019 and back to 2020 all 12 months are shown as expected. Expected behavior: Regards bug: I expect either max year with all 12 months (or up to the last allowed by max) or a current year to be selected by default (or first allowed by min property) Regards feature request: I suggest we have additional property defaultValue. Reasoning: I want some of my date fields to be optional so I can't fill the value before the picker clicked but once user opens drop down I want a specific date to be preselected, specifically I need today or tomorrow but could be any arbitrary date. Also for optional fields would be nice to have some way to clear the field from previously entered value. Steps to reproduce: Related code:
Ionic info: (run
|
@manucorporat Any progress on this? It would be really great if I had the ability to set default dates that haven't been selected to today's date. Or at the very least, do you guys have a sort of work around that could work as a temporary patch-up solution? |
Yes, this is pretty important functionality. Common user expectations are for the datepicker to have today's date selected by default. |
I made a PR that sets the default picker values to today. It doesn't completely fix this bug since you can't change the default to an arbitrary date, but I think that's fine for most use cases. |
I have been toying with this lately. I have a datetime field that is optional, so I do not want to populate the ngModel. However on opening the picker, the current date should be presented. However I think this is a narrow solution as the developer should be able to pass any value in as an input as the pickerDefault. Posting this here as it is a slightly different take on what has been suggested above. So after a bit of hacking I think I'm on the right path. datetime.js L451
The problem here is getting optValue. It takes this from _this.getValue() which will return the model Value. Since we want separation between the picker default and the passed model value this must be changed. Replace the call to _this.getValue() with a call to an new function:
If there is no valid date being passed then use this.pickerDefault which I have declared:
So now you can call it thusly:
or more realistically pass in a function that returns an ISO string of whichever date is applicable. This works for me but I felt like an absolute novice poking around the innards of the Ionic component code so I'm not really sure what I was doing. I'm hoping this could inspire a developer to make what should be an easy modification. Cheers |
Also waiting for this feature as the current behaviour is not really user friendly. |
This is THE most important feature that needs to be there. I would term it as bug instead of feature request. |
I've created PR for this issue: #12698 |
As discussed here, what is a likelihood of a presentWith or default value property being implemented for Datetime? Like the other comments having the date starting on the MAX value is not very user friendly especially when setting the date value in advance is not an option. Has anyone found a work around which does not involve setting the ngModel value? Is there a way to listen or an event when the DateTime modal is open? Appreciate any comments or possible work arounds. Thanks. |
need this feature also, I hope ionic team update this as soon as possible. |
I found a solution, look at this stackoverflow |
Ionic Guys would really appreciate if you can give an update on this. Current I have heard a lot of end clients say
|
Any update on this? |
As there are valid use cases for using min, max, or the current time, you could have convenience values to pass in. So...
|
Fixed in 3.7.1. Should satisfy all of the above. use |
That’s not accurate, it should work as a plain property...
On Sun, Oct 1, 2017 at 12:32 PM MikeCIDFG ***@***.***> wrote:
Thanks mlynch - works perfectly!
To clarify for those Googling this but still new to how Ionic & Angular
work, use (initialValue) ... Using initialValue alone doesn't work.
<ion-datetime displayFormat="MM/DD/YYYY" formControlName="someDate"
(initialValue)="10/01/2017"></ion-datetime>
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#9846 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAArzuBLHf-SSgJJyKgsmFEoL82l8Fy0ks5sn8yXgaJpZM4LZN2O>
.
--
Max Lynch
Co-founder of Ionic
max@ionic.io
414-530-9687
|
Well, it doesn't in my case. Only event binding with parentheses (as shown below) works for me. "Banana Box" two-way binding Might be a quirk of my setup, or using Reactive form instead of template-driven form? In any case, the following works as expected for me w/Ionic 3.10.3, and I thought that note might be of help to others if they encounter the same issue:
|
Try an ISO formatted date: @mlynch, Any way it could be smart enough to pick up on your ...or a note in the docs saying it must be ISO (never mind, it's already there). |
I'm having an issue with initialValue and using displayFormat/pickerFormat to allow the user to only adjust the times.
If the item is empty and you pick a time, it'll save just the h:mm and not in the valid Date format. But if there's an existing time, it'll save the thing in the correct format.
Maybe I'm doing it wrong? |
initialValue doesn't work for me. My code is:
I've tried using initialValue as a plain property, tried using a function that returns the date string and also tried to put the value format as displayFormat instead of ISO but none of them work. Any ideas? |
@tamiris-fonseca |
@zakton5 none of them work. |
I have the following Code and it is not working too:
|
initialValue="2017-10-18" doesn't work for me also |
are you sure you're running ionic 3.7.1? https://github.com/ionic-team/ionic/blob/master/CHANGELOG.md
|
you are right, I am not using 3.7.1. Thanks |
I'am using 3.7.1... but initialValue is not working because its only a solution for kukipei's problem. and "setValue" i can set the date to a initial value. |
@d4ex can you please show us an example about how you set the initial value via @ViewChild? |
I have a Datepicker like this one in the html file: In the typescriptfile i use the following code to get the Viewchild: ... and before open of the datePicker is called i use 'setValue' to set a initialValue:
|
I am using ionic 3.10.3 I also tried both |
@whitecat - To check your Ionic Framework version, you can run
You can also query NPM to find out what version of |
You are correct, that is why it is not working. I am on 3.6.0 |
This is unfortunately not good enough. The initialValue needs to be visible immediately in the field when set, not only after picker is opened and done is hit. The behaviour i'm getting now on 3.9.2 is that the field is initially empty |
To have the value presented on the field immediately, add this code after this._initialize(): |
@misterti see #13292 (comment)
|
Hi, |
Then we need a way for ion-datetime to present an "initial" value in the field |
@misterti - what exactly are you attempting to accomplish here? You mention using If I had a bunch of objects and a standard input in a regular old Angular CLI app, I would do something like:
If I needed to initialize the So it would be basically the same for
And again if The idea behind the (somewhat awkwardly named)
|
I had to do a transformation of the date before presentation, so i tried [(ngModel)]="transformationFunction(item.startDate)" in a ngFor, but that didn't work. Doing transformation in typescript before presentation and only putting [(ngModel)]="item.startDate" indeed works and also changes the list model accordingly. Thank you for clarifying. |
What about the default label value? I have a form where there are two different However, no matter how hard I try, when I'm just doing time with a |
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. |
Ionic version: (check one with "x")
[X] 2.x
I'm submitting a ... (check one with "x")
[X] feature request
Current behavior:
Currently to have the DateTime object open with a value (other than the max value) you must set the ngModel value for the object before the DateTime is opened. Sometimes this isn't desired, such as when you'd like to leave the field blank if the user does not input a date.
Expected behavior:
Adding parameters to start the DateTime at a certain date, like today, will enhance usability. For example, if my date selection range is from 2000 - 2025, but the users most often select a date within a few weeks of today, it would be much easier to start the DateTime interface with today's date instead of 1-1-2025.
Steps to reproduce:
Open DateTime.
Ionic info: (run
ionic info
from a terminal/cmd prompt and paste output below):The text was updated successfully, but these errors were encountered: