You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DateTime doesn't allow adding Picker buttons or Clearing Value #7333
I'm trying to utilize the DateTime component, but need a way to allow the user to "clear" the field (i.e. remove the value). The DateTime API docs mention that you can pass in the pickerOptions, but when I try to pass in an array of buttons, I see that they're overwritten with the default Done/Cancel butttons
You can see in datetime.ts that the buttons property is overwritten during instantiation, just after it was merged with the pickerOptions that were sent in.
Is there a suggested approach for removing the value from one of these DateTime controls?
Thanks for the issue! I am going to close this issue as the original issue has been fixed and you are able to pass buttons now. There is still an open issue with the handler function here: #11641
@Simpler1 The handler function was not being copied/called using our deepCopy. This change makes it so you can pass a handler function to the picker, for example:
Thanks @brandyscarney that worked.
But when I open the date picker first time everything works as expected but on second time the done and cancel button repeats again and again in the row
Please Look at the screen shots
Here is an another solution. Hope someone will get help from the solution: <ion-item> <ion-label><ion-icon name="calendar" item-left></ion-icon></ion-label> <ion-datetime style="position: relative;left: -43px;" name="birthday" [(ngModel)]="birthday" type="date" placeholder="Date Of Birth" displayFormat="YYYY-MM-DD"></ion-datetime> <ion-label *ngIf="birthday!=''" (click)="birthday=''" style="position: relative;left: 109px;"><ion-icon name="close" item-right></ion-icon></ion-label> </ion-item>
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.
Activity
jgw96 commentedon Jul 15, 2016
Hello, thanks for opening an issue with us! Would you be able to provide a plunker that demonstrates this issue? Thanks for using Ionic!
marpstar commentedon Jul 17, 2016
See example here. http://plnkr.co/edit/Xm0yw3UpxAIi8NSEzyIV?p=preview
Note my
home.htmlfile where I'm trying to pass apickerOptionsobject into theion-datetimeto add a "Clear" button to my DateTime.7freaks-otte commentedon Jan 12, 2017
The problem lies in line 479 of the datetime.ts where pickerOptions.buttons get overwritten by [Cancel, OK] (https://github.com/driftyco/ionic/blob/master/src/components/datetime/datetime.ts#L479)
The user pickerOptions.buttons provided by
<ion-datetime [pickerOptions]="{buttons: [...]}"></ion-datetimeshouldn't be overwritten. I guess it would be a 5min 2line-hack to set [OK, Cancel] before and let the buttons be overwritten. I would be really glad to see this implemented soon as I would need a "Clear-Button" too...mwager commentedon Feb 28, 2017
How is the status of this issue? I would like to use the
pickerOptions.buttonsoption too (https://github.com/driftyco/ionic/blob/master/src/components/picker/picker-options.ts).Also note that
deepCopywould remove thehandlerfunctions anyway!See https://github.com/driftyco/ionic/blob/master/src/components/datetime/datetime.ts#L485
and
https://github.com/driftyco/ionic/blob/master/src/components/datetime/datetime.ts#L488
tmvnk commentedon Apr 5, 2017
Any news? Would like to have an clear value option to datetime
DrMabuse23 commentedon May 30, 2017
Hi we need only a var /* @type {?} / pickerOptions = Object.assign({}, this.pickerOptions);
then the handler still work!
ad this line please https://github.com/ionic-team/ionic/blob/master/src/components/datetime/datetime.ts#L502 here
janpio commentedon May 30, 2017
(Psst, having Pull Requests already there makes it a lot easier to just merge this some time together with other stuff)
brandyscarney commentedon Oct 20, 2017
Thanks for the issue! I am going to close this issue as the original issue has been fixed and you are able to pass buttons now. There is still an open issue with the handler function here: #11641
I have submitted a PR to fix that here: #13202
Simpler1 commentedon Oct 21, 2017
@brandyscarney How can an
ion-datetimevalue be cleared with this change?brandyscarney commentedon Oct 23, 2017
@Simpler1 The handler function was not being copied/called using our
deepCopy. This change makes it so you can pass a handler function to the picker, for example:Simpler1 commentedon Oct 23, 2017
@brandyscarney Thanks. That's exactly what I was looking for.
ishaqbhojani commentedon Nov 7, 2017
@brandyscarney I'm new in Ionic 3 and a bit confused, My package.json dependencies looks like
[email protected] is the latest but my handler function not get called
I don't think that I've got the recent changes you did. Please Help
brandyscarney commentedon Nov 7, 2017
@IshaqBhojaniGenetech The PR that was merged to fix that issue will be in the
3.9.0release: #13202There is a nightly released here if you'd like to try it out sooner:
3.8.0-201711062059. It can be installed by running this command:ishaqbhojani commentedon Nov 8, 2017
Thanks @brandyscarney that worked.
But when I open the date picker first time everything works as expected but on second time the done and cancel button repeats again and again in the row
Please Look at the screen shots
First Time :

Second Time :

Can you please look into this Issue.
fix(datetime): avoid adding cancel and done button repeatedly
brandyscarney commentedon Nov 8, 2017
@IshaqBhojaniGenetech Thank you! I pushed a fix for this and released a nightly:
We plan on releasing a
3.9.1with this fix in. Please let me know if you are still experiencing problems, thanks!garaitapas2 commentedon Jan 25, 2018
Here is an another solution. Hope someone will get help from the solution:
<ion-item> <ion-label><ion-icon name="calendar" item-left></ion-icon></ion-label> <ion-datetime style="position: relative;left: -43px;" name="birthday" [(ngModel)]="birthday" type="date" placeholder="Date Of Birth" displayFormat="YYYY-MM-DD"></ion-datetime> <ion-label *ngIf="birthday!=''" (click)="birthday=''" style="position: relative;left: 109px;"><ion-icon name="close" item-right></ion-icon></ion-label> </ion-item>ionitron-bot commentedon Sep 1, 2018
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.