on 10-30-2014 12:51 PM
Im fairly new to SAPUI5 and when I click on button I get the error in the title what I did in Is I used the SAP web IDE to create new MVC project .
in the main view JS I put
createContent : function(oController) {
var btn = new sap.m.Button({ id:"myBtn", text : "Content Button" }); return new sap.m.Page({ title: "TitleT", content: [ btn ] });
}
in the Main controller JS I put the following code
onInit: function() { var that = this; window.setTimeout(function() { that.byId("myBtn").setVisible(true); }, Math.random() * 10000); }, onPress: function() { this.byId("pressMeButton").setText("I got pressed");
You can manage the control with onInt() and onAfterRendering() methods.
> Step 1 : set a property to manager business rules in onInit() method
onInit: function (oEvent) {
d.flag = true; // d define by global var var d = {};
},
> Step 2 : get property and manage visibility ou destroy properties in onAfterRendering :
onAfterRendering : function (oEvent) {
var n = this.getView().getViewName();
if(n.includes('requirement.edit')){
var s = d.flag;
this._readOnlyItem("ID_CONTROL", )
}
},
// helper to manager UI Control
_readOnlyItem: function (k,s){
try {
(s)? this.getView().byId(k).destroy():null;
}
catch (e) {
console.log("oups... an error occurred while processing your request : " + e) ;
}
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mike,
And as for the solutions:
Kimmo's Solution
View code
var btn = new sap.m.Button(this.createId('myBtn'), {
text: "Content Button"
});
return new sap.m.Page({
title: "Title",
content: [btn],
press:[oController.onPress,oController]
});
Controller code
onInit: function() {
var that = this;
window.setTimeout(function() {
that.byId("myBtn").setVisible(true);
}, Math.random() * 10000);
}, onPress: function() {
this.setText("I got pressed");
}
Another solution I could think of
View code
var btn = new sap.m.Button({
id: "myBtn",
text: "Content Button"
});
return new sap.m.Page({
title: "Title",
content: [btn],
press: [oController.onPress, oController]
});
Controller code
onInit: function() {
var that = this;
window.setTimeout(function() {
sap.ui.getCore().byId("myBtn").setVisible(true);
}, Math.random() * 10000);
},
onPress: function() {
sap.ui.getCore().byId("myBtn").setText("I got pressed");
}
Both the above solutions could be understood by reading the blog.
Regards,
Naren L Naik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In View you need to add one more tag as "l:VerticalLayout"
<l:Grid defaultSpan="L12 M12 S12"
width="auto" id="gridId">
<l:content>
<l:VerticalLayout id="vlContent">
<f:SimpleForm id="SimpleFormChange354"
Your form has to be inside this tag. Now in Controller use command like this
var oGrid = this.getView().byId("vlContent");
oGrid.setVisible(false);
Thus instead of hiding Grid we are hiding VerticalLayout. This will work for sure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Mike,
You need a reference to your view Object and not your controller to get the Controls on the view.
So your code should look like:
onInit: function() {
var that = this;
window.setTimeout(
function(){
that.getView().byId("myBtn"),setVisible(true);
}, Math.random() * 10000
);
}
with best regards
Florian Hafner
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
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.