Allow DateTime to have a starting date without setting the object's value
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):
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.48
ios-deploy version: 1.9.0
ios-sim version: 5.0.11
OS: OS X El Capitan
Node Version: v6.9.2
Xcode version: Xcode 8.2.1 Build version 8C1002
@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: [presentWith]="ISOinCode"
You could pass in something that matches your displayFormat (or pickerFormat if that makes more sense): presentWith="2017/01/01"
If you've set min or max properties, you could use those strings for convenience: presentWith="min" or presentWith="max"
pickerPreset could be an alternative to presentWith.
So just some comment on this
As for a presentWith property, I don't think I see the point of this.
Take for example, the alarm option in ios
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:
- Because the DateTime is inline, and is essentially the whole point of the form, it's impossible for the user to miss.
- There is almost no penalty for a wrong answer; you just delete or edit it.
- Validation is irrelevant since there's no invalid response.
- The user isn't actually expected to choose the current time. The assumption is that they'll change it, but it's a convenient starting point if they want to set an alarm N minutes from now.
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:
- A user might forget to enter dates, the form submission will succeed, and now you have the penalty of bad data in the DB.
- To fix that you have to watch for ionChange event. Then, if the user hasn't changed the value, alert them and ask if they intended to leave the date as-is (I'm actually doing this in one of my flows).
- You've lost out on the default touched/pristine/valid functionality without doing extra work.
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 presentWith property would give users a more convenient starting point regarding the dials, like a souped-up placeholder.
In fact, pickerPlaceholder is another alternative property name to consider.
@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: https://github.com/driftyco/ionic/issues/10710
But it has different details so I copy-paste my post here.
Ionic version: (check one with "x") [x] 2.x
I'm submitting a ... (check one with "x") [x] bug report [x] feature request
Current behavior:
If max attribute specified into future for example "2020-12-31" the date picker would display:
- Day: {1}
- Month: {unselected but list starts with today's month, currently March}
- Year - {the max one, for this example 2020}.
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: See plunker: http://plnkr.co/edit/H7eMFjSDrj8VbsUo0bDW?p=preview
Related code:
<ion-list>
<ion-item>
<ion-label>Due on</ion-label>
<ion-datetime
displayFormat="D MMMM YYYY"
pickerFormat="D MMMM YYYY"
min="2017-03-08"
max="2020-12-31"
></ion-datetime>
</ion-item>
</ion-list>
</
Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):
Cordova CLI: 6.5.0
Ionic Framework Version: 2.2.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.4
ios-deploy version: 1.9.1
ios-sim version: 5.0.11
OS: OS X El Capitan
Node Version: v6.7.0
Xcode version: Xcode 8.2.1 Build version 8C1002
@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
// cool, we've loaded up the columns with options
// preselect the option for this column
var /** @type {?} */ optValue = getValueFromFormat(_this.getValue(), format);
var /** @type {?} */ selectedIndex = column.options.findIndex(function (opt) { return opt.value === optValue; });
if (selectedIndex >= 0) {
// set the select index for this column's options
column.selectedIndex = selectedIndex;
}
// add our newly created column to the picker
picker.addColumn(column);
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:
DateTime.prototype._getValueOrDefault = function () {
if (Object.keys(this._value).length)
return this.value;
else {
var _default = {};
updateDate(_default, this.pickerDefault);
return _default;
}
};
If there is no valid date being passed then use this.pickerDefault which I have declared:
DateTime.prototype.pickerDefault; in DateTime_tsickle_Closure_declarations()
So now you can call it thusly:
<ion-datetime displayFormat="DD MMM YY" pickerFormat="DD MMM YYYY" pickerDefault="2017-08-06" min="2017" max="2020" formControlName="date"></ion-datetime>
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: https://github.com/ionic-team/ionic/pull/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? If so a possible work around is to set the today date value just before the modal box is opened. If the user hits cancel, we can reset the value back to NULL on the datetime event ionCancel. I've tried doing this by using the (click) event but the datetime dialog view is opened before I can set the datetime value through click therefore showing the MAX value.
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 ion-datetime is a bad UX design!
I have heard a lot of end clients say
Its too time consuming to change day, then month and then the year. Even if we want to change just the day from today, it takes a hell lot of time and effort
Any update on this?