Skip to Content
0

new sap.m.Dialog change button to enabled dynamicly

Oct 26, 2016 at 03:08 PM

176

avatar image
Former Member

Hello

I am using new sap.m.Dialog with two buttons

one button should be disabled at first, and after calling a service to get data in the dialog

I have to change it to enabled.

in the Controller.js the code is like this:

In the Controler of the dialog

If the oData_error not equal 'X'

I need to change the button to enabled : true.

Any help will be appreciated.

Thank you.

cart-call.png (17.8 kB)
omodel-read.png (18.5 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Jun Wu Oct 27, 2016 at 03:52 PM
1

bind enabled attribute to model, then in your controller code manipulate the model to enable or disable the button

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Oct 27, 2016 at 08:36 PM
0

You can give id to the button in the view(suppose 'idBtn'). Take control of the button in the function and enable it.

sap.ui.getCore().byId("idBtn").setEnabled(true);

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello Amritpal,

I add the code, and i get:

"Uncaught TypeError: Cannot read property 'setEnabled' of undefined" in the Console

Thank you,

oModel.read(_sRequestUrl, {
    success: function(oData, oResponse) {
        var _oResult = oData.results;  // * results may not exist, you can check in debug
        var _oJsonModel = new sap.ui.model.json.JSONModel(_oResult );
//        oView.setModel(_oJsonModel);
        oResultField.setValue(oData.LGOBE); 
    sap.ui.getCore().byId("Return_ord").setEnabled(false);
        console.log(oResultField);
0
Former Member
Former Member

Hi,

I see that the property name for id in your code is 'ID'(uppercase).

Change it to id(lowercase) and it should work.

0
Former Member
Former Member

Hello Amritpal,

Thank you for your replay,

now it seems to be working.

Thank you.

0
Akhilesh Upadhyay Oct 27, 2016 at 06:13 PM
0

its good to set enabled/disable using model property, but you can try below code inside your condition:

var oLeftBtn = $( "button[id*='"+this._orderDialog.getLeftButton()+"']" ).control()[0];
oLeftBtn.setEnabled(true);

Regards,

Akhilesh

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member
Oct 30, 2016 at 05:05 PM
0

I will go with Jun Wu approach and never use setEnabled function because you have more flexibility when you use model.

Please take a look at http://jsbin.com/ticenu/edit?js,output

and change the result value in the setTimeout function to true and false to see how it works.

Thanks

Dennis

Share
10 |10000 characters needed characters left characters exceeded