on 2014 Sep 30 4:49 PM
Hi All,
I have an XMLview in which I have a button on it, which is disabled. Defined using the following code: -
<Button id="rejectButton" enabled="false" text="Delete" type="Reject"
icon="sap-icon://delete" press="onDelete" />
The app is a split view. This button appears on the detail view. Now, I want to be able to click an entry in the master view and in turn enable this button.
I am failing miserably. I presume I may need to get hold of the button ID and somehow set the enabled to true. I am thinking I need to be using the sap.ui.getCore() thingy, but do not know how to specify an ID.
Could someone point me in the right direction of how to get the button element, so that I can enable it. Or if this is the wrong solution, tell me how I should be enabling it.
Thanks
Martin
Request clarification before answering.
Hi,
So this is possible programatically (but not recommended) by using
sap.ui.getCore().byId("idViewRoot--idViewDetail--rejectButton")
This should get you the button object.
Note that you have to specify the id of not only the button but also the view hierarchy it is placed withing (idRootView => idViewDetail) so if you move the button or change any higher up ids, then you have to change the code.
Using a local state JSON model, as suggested, is preferable and you can bind other things to the semantic action of enabling the button if needed with no more code. You also have the freedom to change the UI from the button logic and it makes use of the framework to do all the heavy lifting.
Hope this helps!
Oli
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A bit off-topic, but as a reminder when using XML views you should use
this.getView().byId("rejectButton");
instead of
sap.ui.getCore().byId("the--whole--dreadful--view--layout--id--to--your--rejectButton");
However, of course the recommended approach is not to get a reference to the control and use the setEnabled() method, but to use a local JSON model to bind these UI properties as you and Jason Moors correctly stated
Hi Robin,
Yes this is true but only if the required control is within the current view. The view.byId function searches only within itself. It actually prepends the current views' id to the id passed to that function and uses the sap.ui.core.byId function.
The OP wanted to change a control in a different view hierarchy and so the only way to do it by id is to specify the entire thing.
The best way is to use a little local JSON state model though as it puts all the hard work on the framework.
Oli
I normally just bind the enabled property to a model, and then update the model.
Here's a simple example.
http://jsbin.com/soqiluxedalo/1/edit
Regards,
Jason
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Quick update.
I "inspected" the element in Chrome and it had the ID "idViewRoot--idViewDetail--rejectButton".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.