on 02-21-2019 2:08 PM
Hi! I have view that contains fragment in uxap block. Fragment does not have id. This fragment contains few inputs (DatePickers). I want to get access from one input to another when onChange event is fired.
Part of view
<mvc:View
controllerName="name_of_controller"
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns:uxap="sap.uxap"
xmlns:ino="sap.ino.controls"
afterRendering="onAfterRendering"
xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1">
<Page id="some_id"
...
<uxap:ObjectPageLayout
id="objectpage"
useIconTabBar="true"
enableLazyLoading="true"
visible="{view>/objectExists}">
<uxap:headerTitle>
...
</uxap:headerTitle>
<uxap:sections>
<uxap:ObjectPageSection id="sectionDetails" title="{i18n>MENU_MIT_DETAILS}">
<uxap:subSections>
<uxap:ObjectPageSubSection id="mainsubsection" title="{i18n>MENU_MIT_DETAILS}">
<uxap:blocks>
<core:Fragment fragmentName="fragment_with_datepickers" type="XML" />
</uxap:blocks>
</uxap:ObjectPageSubSection>
</uxap:subSections>
</uxap:ObjectPageSection>
Inputs are put in fragment dynamically.
If I write next code then returns undefined
oFieldControl.attachChange(function() {
var oDatePicker = oController.byId("id_of_needed_control"); // Returns undefined
});
Use of sap.ui.core.Fragment.byId() also helpless because the page is not drawn completely, the page is not drawn completely because I add id for <core:Fragment fragmentName="fragment_with_datepickers" type="XML" />
oFieldControl.attachChange(function() {
var fragmentId = oController.getView().createId("fragment_id");
var oDatePicker = sap.ui.core.Fragment.byId(fragmentId, "id_of_needed_control");
// or
// var oDatePicker = oController.byId(sap.ui.core.Fragment.byId(fragmentId, "id_of_needed_control"));
});
Hi Denis Kitrish,
No probs, you can delete the answer and put it in the comment as well.
I was asking you for the code where you add the date buttons. But I guess i understand your issue.
1. If you are adding the controls in the controller by some hardcoded id then you need to access them via below:
sap.ui.getCore().byId("yourCntrlId");
2. If you don't want to do that, then you need to use createId function to generate the id
this.getView().byId("page").addContent(new sap.m.Button({
id: this.createId("test1"),
press: this.custBtnPress.bind(this)
}));
// Now the code will work
this.getView().byId("yourCntrlId");
BR,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
maheshkumar.palavalli Thank you very much. sap.ui.getCore().byId is helpfull
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But that is not a better way, instead you can use the createId() to generate the id for you which will be better as the ID wlll be specific to your view.
You can actually click on comment and reply there 😛
Please mark the answer as answered and close the question
BR,
Mahesh
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.