Skip to content

bug: ion-datetime hasValue returning true, regardless of control value #18540

Closed

Description

@kelvindart

Ionic version:
[x] 4.x

Current behavior:
The hasValue() method on ion-datetime always returns true, due to the way the underlying value is stored - the check determines if Object.keys(...) has a length, which is always true in the case for ion-datetime since the underlying value is always an object.

This results in various behaviour occurring as if the ion-datetime has a value, even if it doesn't. For example, item-has-value is added to the wrapping ion-item which affects floating labels, and additional styling around this class.

Expected behavior:
For hasValue() to return true if the ion-datetime has a value, or false if not.

Steps to reproduce:

  1. Add an ion-datetime wrapped inside an ion-item to a page.
  2. Load the page.
  3. Observe how the ion-item has the class item-has-value prior to being set to anything.

Related code:

HTML

<ion-content color="medium">
  <ion-item>
    <ion-label>Date/time</ion-label>
    <ion-datetime></ion-datetime>
  </ion-item>
</ion-content>

SCSS

ion-content {
  --background: grey;
}

ion-item {
  --background: transparent;

  &.item-has-value {
    --background: white;
  }
}

Other information:
PR: #18541

Ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.12.0 (/Users/kelvindart/.nvm/versions/node/v10.15.3/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.5.0
   @angular-devkit/build-angular : 0.13.9
   @angular-devkit/schematics    : 7.3.9
   @angular/cli                  : 7.3.9
   @ionic/angular-toolkit        : 1.5.1

System:

   NodeJS : v10.16.0 (/Users/kelvindart/.nvm/versions/node/v10.15.3/bin/node)
   npm    : 6.9.0
   OS     : macOS High Sierra

Activity

  1. added
    package: core
    type: bug
    on Jun 14, 2019
  2. added a commit that references this issue on Jun 27, 2019
    92e0f98
  3. ionitron-bot commented on Jul 27, 2019

    @ionitron-bot

    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.

  4. locked and limited conversation to collaborators on Jul 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: coretype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions