question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: ion-datetime custom button with role="cancel" still updates value

See original GitHub issue

Bug Report

Ionic version: [x] 4.x

Current behavior:

I use the pickerOptions property of the ion-datetime to add buttons with custom handlers. I add a “Cancel” button with role: 'cancel'. When I click that cancel button, the value of the ion-datetime changes anyway.

Expected behavior:

A picker button with role cancel should not change the ion-datetime’s value.

Steps to reproduce:

<ion-datetime display-format="YYYY" value="2019" />
document.querySelector('ion-datetime').pickerOptions = {
  buttons: [
    { text: 'Cancel', role: 'cancel' },
    { text: 'Done', handler: columns => console.log(columns.year.value) },
  ],
};

Related code:

https://codepen.io/simonhaenisch/pen/YzPwYZa?editors=1010

Other information:

I think #19441 is about the same issue but not sure.

This is the code that looks like it should be working:

https://github.com/ionic-team/ionic/blob/6e0b9c45489889266620ee2ca38c33fdf8ce3f3b/core/src/components/picker/picker.tsx#L166-L170

Ionic info:

@ionic/core: 4.11.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
ipacbalajcommented, Mar 4, 2021

Do you have any updates on this?

As a quick fix I added an @ngIf on the component and I am reinitializing the compnent in the cancel handler.

image image

2reactions
dingzhanjuncommented, Nov 20, 2020

this is still true with ionic/react 5.5.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

ion-datetime - Ionic Framework
This component displays buttons which show the current date and time values. When the buttons are tapped, the date or time pickers open...
Read more >
How to use the Ionic 6 Datetime component - YouTube
In this video we are taking a closer look at the Ionic 6 datetime component and implement a stylish modal that works for...
Read more >
Ionic 6 ion-datetime | Complete guide - YouTube
Hello Friends, Welcome Back to @CodingTechnyks. In this video, we are going to work with Ionic 6 ion-datetime using​ #ionic #angular for ...
Read more >
@ionic/core | Yarn - Package Manager
Ionic is an open source app development toolkit for building modern, fast, top-quality cross-platform native and Progressive Web Apps from a single codebase ......
Read more >
Ionic v4 datepicker clear button? - angular - Stack Overflow
Based on what I'm reading I would be tempted to open a bug on Ionic to say that the feature is essentially unusable....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found