How to validate not nullable sap.ui.model.type.DateTime?
See original GitHub issueOpenUI5 version: 1.54.8
URL (minimal example if possible): http://plnkr.co/edit/D8EXpuOUmhu5JuI2k508?p=preview
- Steps to reproduce the problem:
- Input something in DateTimePicker, leave focus
- 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.
Meanwhile, keep date check in DateTimePicker:
What happens instead?
-
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 ? -
set
minLength: 1
works in Input, but not in DateTimePicker(no Error State):
Input:
- set
minimum: 1
works, but with strange value state text:
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
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:
- Created 5 years ago
- Comments:8 (4 by maintainers)
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.typeHi @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).