0

I'm trying to pass json to a function, which in turn takes the json and displays dynamic ui-modal dialog. When I try to pass the button events(functions) , thy are getting executed and returning undefined how can I pass reference to the function instead of actual function. Sorry for my english the code below explains much better:

//heres my ui model function
function showDialog(json) {
        var dialog_id = json.id;
        if(typeof($(dialog_id)[0]) === "undefined") {
            $(body).append("<div id='dialog-confirm'></div>");
        }
        $(dialog_id).html(json.confirmationText);
        $(dialog_id).dialog({
            modal: true,
            title: json.title,
            height: 250,
            width: 400,
            buttons:json.buttons
        });

}

//here is the function which calls
showDialog({"id":"#dialog-confirm","title":"blaa","confirmationText":'randomtext',"buttons":[{"text":"Cancel","click":window["noAction"]},{"text":"Confirm","click":window["doAction"]('pram1','param2')}]});

var noAction = function(){$('#dialog-confirm').dialog('close');}
var doAction = function(param1,param2){//do some logic};

noAction function is working correctly. (when the model is called and cancel is clicked the dialog disappears)

doAction function is getting evaluated when the function showDialog is called and is returning undefined (verified in console). How can I bind doAction to confirm button. (ie, when Confirm is clicked I want to call doAction).

P.S: I know how to do it with custom on click handlers but I think it would be a work around but not the actual solution.

Any help is greatly appreciated. Thanks in advance!

Nishanth Matha
  • 5,993
  • 2
  • 19
  • 28

1 Answers1

1

try showDialog({..., "buttons":[...,{"text":"Confirm","click":function(){doAction(param1,param2);} }]})

cresjie
  • 469
  • 2
  • 13
  • yep tried it...same behavior the function is getting evaluated as soon as the showDialog is called.. I want it to execute only when Confirm is clicked. Thanks – Nishanth Matha Mar 11 '16 at 01:56
  • thanks though your answer didn't solve my problem it helped me in what I was doing wrong :) upvote – Nishanth Matha Mar 11 '16 at 02:16