Configuring jQuery dialog button callback

Hi, coders, I would like to initialize a dialog box with a callback function, for example, for the "Save" button, but I want the callback to be as a standalone function, and not defined inline using the function () {....} The code snippet below emphasizes what I want to do.

$( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
            "Save": saveAction() 
...
function saveAction()  
{  
}  

What is the correct syntax for the "Save" line: saveAction () because it does not work?

thank

+3
source share
3 answers

Parany then saveActionforced to perform a function. Use this instead:

        "Save": saveAction
+3
source

saveAction , : saveAction (a, b, c), :

"Save": saveAction({a = "val", b = "val", c = "val"})
0

If you need to pass parameters, you must transfer your function call to an anonymous function definition, for example:

"Save": function() { saveAction({a = "val", b = "val", c = "val"}) }

This effectively defines a new anonymous function that takes no parameters, and which, when executed, will call your own function with your desired parameters.

0
source

Source: https://habr.com/ru/post/1788706/


All Articles