openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

Sap.m.DatePicker returns value in wrong format in some cases

Open eldorak90 opened this issue 8 years ago • 2 comments

OpenUI5 version: 1.50.6

Browser/version (+device/version): Windows 10, MS Edge 40.15063.674.0

Any other tested browsers/devices(OK/FAIL): Windows 10, Google Chrome 62.0.3202.94 (FAIL)

URL (minimal example if possible): https://jsbin.com/vafujaruni/1/edit?html,js,output

User/password (if required and possible - do not post any confidential information here):

Steps to reproduce the problem:

  1. Pick a value with the date picker (e.g. 12/05/17 in sample)
  2. Change the value manually to a four digit year (e.g. 17 -> 2017)

What is the expected result? Returns the value in format defined by setValueFormat() method (in sample, 2017-12-05) or declare the value as invalid because there are 4 digits than the 2 defined so clear the field and return empty. But it mustn't return the date in a wrong format.

What happens instead? Returns the value in format 12/05/2017

Any other information? (attach screenshot if possible) By picking a value the picker works completly fine. Also if the value is entered manually in the correct format. It's just the case above which doesn't work correctly.

eldorak90 avatar Dec 05 '17 13:12 eldorak90

I've created an internal incident 1780475023 . The status of the issue will be updated here in GitHub.

awui avatar Dec 07 '17 15:12 awui

Hi,

According to the documentation:

If the string does NOT match the displayFormat (from user input) or the valueFormat (on app level), the sap.ui.core.format.DateFormat makes an attempt to parse it based on the locale settings.

If the value entered does not match the displayFormat, than the value is not valid and the value will be returned as is. Most UI5 input controls are designed to accept any input that will be validated on some point in time.

In your case the input "12/05/2017" is not valid so the value entered is returned as is. In the change handler function a boolean param "valid" contains the result of the validation.

Try changing your change handler like this:

    .attachChange(function(event){
      console.log(event.getSource().getValue());
      console.log(event.getParameter("valid"));
    }

Cheers!

testojs avatar Dec 19 '17 14:12 testojs