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.

How to validate not nullable sap.ui.model.type.DateTime?

See original GitHub issue

OpenUI5 version: 1.54.8

URL (minimal example if possible): http://plnkr.co/edit/D8EXpuOUmhu5JuI2k508?p=preview

  • Steps to reproduce the problem:
  1. Input something in DateTimePicker, leave focus
  2. Clear value in DateTimePicker, leave focus
  • What is the expected result?

When there is not datetime in DateTimePicker, value state is Error and value state text is meaningful. image

Meanwhile, keep date check in DateTimePicker: image

What happens instead?

  1. set nullable: false did not work both in DateTimePicker & Input, this should work according to https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.type ? image

  2. set minLength: 1 works in Input, but not in DateTimePicker(no Error State):

Input: image

  1. set minimum: 1 works, but with strange value state text:

image

I did not found minimum in doc, but found it in https://sapui5.hana.ondemand.com/resources/sap/ui/model/type/Date-dbg.js

It seems only constraints validation for minimum and maximum image


I also tried this in change event:

onValidateDate: function(oEvent) {
  var oSource = oEvent.getSource();
  var sValue = oSource.getValue();

  // not sure this is the right way
  if (sap.ui.core.format.DateFormat.getDateTimeInstance().parse(sValue)) {
    oSource.setValueState("None");
    return;
  }
  oSource.setValueState("Error");
}

But

if sValue is “”, parse() returns null, value state is set to Error in onValidateDate, but it will immediately changed back(None state) by DateTime validation. Or I can remove DateTime type in xml ? But I’d like to use build in type validation.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
devtomtomcommented, Nov 6, 2018

Hello @TinaC,

Regarding the nullable I guess you have mixed up two things: nullable is not supported in the sap.ui.model.type.DateTime https://sapui5.hana.ondemand.com/#/api/sap.ui.model.type.DateTime but a concept of the OData types https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.type

1reaction
clemaicommented, Nov 7, 2018

Hi @TinaC,

the problem here is that our framework validation is done asynchronously, and the ValueState set by your onChange handler is overruled. This is just the way our framework does validation, and no bug in my opinion.

IMO the only correct way from framework perspective to achieve what you want is to use the “minimum” constraint, but I agree with you that the shown error message isn’t meaningful. I will talk with the responsible colleagues about the error text. Edit: Minimum constraint also makes no sense here.

The alternative solution would be disabling the framework validation and do the validation on your own, create own messages (sap.ui.core.message.Message), and add them to the MessageManager (sap.ui.core.message.MessageManager).

Read more comments on GitHub >

github_iconTop Results From Across the Web

DatePicker/TimePicker with sap.ui.model.odata.type.DateTime?
Since sap.m.DateTimeInput is now deprecated I wonder how to input Date and Time of a sap.ui.model.odata.type.DateTime with Two-Way-Binding ...
Read more >
Type Determination - Documentation - Demo Kit - SAPUI5 SDK
The property binding automatically determines the appropriate type depending on the property's metadata, unless a type is specified explicitly.
Read more >
How to Add Date / Time from OData Service Correctly to UI?
In our case, the appropriate type for displaying the value of Edm.Time is sap.ui.model.odata.type.Time . Sample. From https://embed.plnkr.
Read more >
Model validation in ASP.NET Core MVC | Microsoft Learn
A value is considered present only if input is entered for it. Therefore, client-side validation handles non-nullable types the same as nullable ...
Read more >
Working with Data - SAP Capire
This section describes how data is represented and used in the CAP Java SDK. ... CDS models, the following SAP HANA-specific data types...
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