cancel
Showing results for 
Search instead for 
Did you mean: 

Date Picker Validation

delmiranda
Participant
0 Kudos

Hi Experts,

I'm trying to validate my form referring this code

https://sapui5.hana.ondemand.com/#/entity/sap.m.Input/sample/sap.m.sample.InputChecked.

All the input are working fine but the date picker is still on error state even I already selected the Date.

here is the XML code

<f:fields>
	<DatePicker id="inputPaidOn" dateValue="{ path : 'paymentModel>/paidOn', type : 'sap.ui.model.type.Date', constraints : { minLength: 1, maxLength: 120 } }" required="true" valueFormat="MMM d, y"/>
</f:fields>

controller

_validateInput: function(oInput) {
	var sValueState = "None";
	var bValidationError = false;
	var oBinding = oInput.getBinding("value");

	try {
		oBinding.getType().validateValue(oInput.getValue());
	} catch (oException) {
		sValueState = "Error";
		bValidationError = true;
	}
	oInput.setValueState(sValueState);
	return bValidationError;
},

onSubmitPayment: function(oEvent) {
	.....
	var oCore = sap.ui.getCore(),
	aInputs = [
		oCore.byId("inputAmount"),
		oCore.byId("inputPaidBy"),
		oCore.byId("inputPaidOn"),
	],
	bValidationError = false;

	// Check that inputs are not empty.
	// Validation does not happen during data binding as this is only triggered by user actions.
	aInputs.forEach(function(oInput) {
		bValidationError = this._validateInput(oInput) || bValidationError;
	}, this);

	if (!bValidationError) {
            //....myOdata create
        }
}

Additionaly when I'm getting error on my console.log (Log-dbg.js)

The given date instance isn't valid. -

Also I'm getting error with my property Binding with "paidOn: null"


FormatException in property 'dateValue' of 'Element sap.m.DatePicker#inputPaidOn': Don't know how to format Date to object

Hint: single properties referenced in composite bindings and within binding expressions are automatically converted into the type of the bound control property, unless a different 'targetType' is specified. targetType:'any' may avoid the conversion and lead to the expected behavior.

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor

you bind to dateValue for datePicker

how this one can work? oInput.getBinding("value");