0

I have a sample of icons in a HBox in an XML view as below:

<m:HBox>
  <core:Icon src="sap-icon://show" color="#007bff" id="test1"  press="onPressView" />
  <core:Icon src="sap-icon://edit" color="#007bff" id="test2" press="onPressEdit" />
  <core:Icon src="sap-icon://print" color="#007bff" id="test3" press="onPressPrint" />
</m:HBox>

In controller to set visible false, I am doing as:

let testIcon1 = this.getview().byId('test1');
testIcon1.setVisible(false);

But this isn't working.

0

1 Answer 1

2

You're probably accessing a template control instead of the actual rendered one. If you inspect the element in the devtools, see if the ID of the rendered control (Icon) has the suffix __clone<n>.

Since such ID suffixes are generated by the framework, accessing cloned controls via byId should be avoided. There are many alternative solutions in such cases. A general good solution is to separate views from the controller by binding the control properties (e.g. visible) and manipulating those properties from the model.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.