Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller Code for Sample Input Checked does not work #3693

Closed
simonarangelova opened this issue Feb 2, 2023 · 4 comments
Closed

Controller Code for Sample Input Checked does not work #3693

simonarangelova opened this issue Feb 2, 2023 · 4 comments

Comments

@simonarangelova
Copy link
Contributor

OpenUI5 version: 1.110

Browser/version (+device/version):

Any other tested browsers/devices(OK/FAIL):

URL (minimal example if possible): https://ui5.sap.com/#/entity/sap.m.Input/sample/sap.m.sample.InputChecked

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

Steps to reproduce the problem:
The sample for Input - Checked (https://ui5.sap.com/#/entity/sap.m.Input/sample/sap.m.sample.InputChecked) does not work.

In the Controller code https://ui5.sap.com/#/entity/sap.m.Input/sample/sap.m.sample.InputChecked/code/C.controller.js the function _validateInput needs to be corrected.

What is the expected result?

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

	try {
		oBindingInfo.type.validateValue(oInput.getValue());
	} catch (oException) {
		sValueState = "Error";
		bValidationError = true;
	}

	oInput.setValueState(sValueState);

	return bValidationError;
},

What happens instead?

_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;
},

Any other information? (attach screenshot if possible)
This issue is moved from SAP-docs repository
sebastianesch commented (SAP-docs/sapui5#37 (comment))

@boghyon
Copy link
Contributor

boghyon commented Feb 6, 2023

Hi @sebastianesch ,

the function _validateInput needs to be corrected

Could you please elaborate on why exactly oInput.getBinding("value") needs to be changed to oInput.getBindingInfo("value")? The sample seems to be working fine.

Also, ManagedObject#getBindingInfo is a protected API.

@sebastianesch
Copy link

Hi @boghyon,

sorry, I did not notice that getBindingInfo is protected. When I try the example with getBinding the return value is undefined:

image

getBindingInfo returns the Binding information defined in the view.

Kind regards,
Sebastian

@sebastianesch
Copy link

Hi @boghyon,

I debugged the UI5 sample and can confirm that it works. In our case the Binding Info object was missing the binding property and as getBinding uses return oInfo && oInfo.binding;, it would not return the binding:

image

The root cause for the issue was that our binding definition in the view contained path : '{/name}', instead of path : '/name',. Removing {} fixed the issue and the example works.

<Input
			id="nameInput"
			class="sapUiSmallMarginBottom"
			placeholder="Enter name"
			valueStateText="Name must not be empty. Maximum 10 characters."
			value="{
				path : '{/name}',  <!-- {} breaks binding info -->
				type : 'sap.ui.model.type.String',
				constraints : {
					minLength: 1,
					maxLength: 10
				}
			}"
			change= ".onNameChange" />

Sorry for the inconvenience and thanks for the help.

Kind regards,
Sebastian

@boghyon
Copy link
Contributor

boghyon commented Feb 6, 2023

@sebastianesch No prob, thanks for the replies! You might want to subscribe to SAP/ui5-language-assistant#82 and SAP/ui5-language-assistant#563 which, if the requested feature(s) were ever implemented, could detect invalid values such as path: '{/name}'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants