on 08-20-2015 9:20 PM
Hi, How to get an Control using the byId? But the Control is inside a list, and this list is inside a fragment. This is the code to add the fragment:
This is the fragment:
In the controller, all of these return undefined:
this.getView().byId("myIpt")
sap.ui.core.Fragment.byId("myFragment","myIpt")
sap.ui.getCore().byId("myIpt")
* As you can see in the input I have add an event the liveChange, with a breakpoint I can see that the input Id is:
oControlEvent.getSource().getId() === "__xmlview3--create--myFragment--myIpt-__xmlview3--create--myFragment--myList-0"
The only way I found to get the input was by removing the id from the fragment ("myFragment") and with the following:
this.getView().byId("myList").getItems()[0].getContent()[0].getItems()[2]
Bu in my opinion this is going to give me a lot of headaches in the future with maintenance.
What I want to do is something similar to "byId", but it is not working, so I need help to understand why this does not work, and directions to the best solution.
thanks Cristiano.
Hi Cristiano,
You are unable to access the Input field using byId as depending on the data in the List there will be multiple instance of the Input field i.e. myList-0 .....myList-9 and so on.
The only way to get the value in the Input field will be as mentioned by you as below:
this.getView().byId("myList").getItems()[0].getContent()[0].getItems()[2]
Hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cristiano
Since you have a input in a item in a list, depending on the number of items in the list, there are going to be many instances of the input. For instance, you have 10 items in the list and you are going to have 10 inputs. Do you want to get the 10 input controls?
Thanks
-D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Christiano,
For Dynamic, you could use a jQuery to get control Id.
I tried with selectionChange event of a list and input ID of custom list Item, Check the sample here - sap.m.List Input ID Sample
And the code will be for you -
selectionChange : function(oEvent){
var oSelectedIndex = oEvent.getParameter("listItem").getId().slice(-1);
var oSelectedInputId = $('#myList').find('.sapMInput')[oSelectedIndex].id; //Your selectedInputID
alert(oSelectedInputId);
alert(sap.ui.getCore().byId(oSelectedInputId).getValue());
}
But, I was not sure about the scenario, like you need it in selection event or select of some button. However, the above logic works for any scenario just some tweak required on how you use it.
Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.