Search code examples
javascriptpdfdialoglivecycle-designer

How to use multiple OK Buttons in an Adobe-JS Custom Dialog Box?


I'm making a custom dialog box with Adobe Livecycle Designer ES2 and I can't find out how or even if it's possible to get two type:"ok"-Elements in there doing different things.

I want to have one regular OK-Button at the bottom and I want to have a hyperlink to a website on the top.

That already prevents me of being able to use "ok_cancel" et cetera, because as far as I know those buttons aren't separable in the layout.
I don't know how to make the event-handler for the button where I would launch the URL or if it's even possible to handle the click event of "ok"-Elements outside of "commit".
Also I don't understand how the "commit" function chooses its ok-button, because in another Dialog Box of mine it's triggered by the lower OK-Button which is on the bottom of the code unlike in this case where the upper button triggers the "commit" function.

Here's my code to make it clearer - I don't want the "link" element to trigger "commit" but the "okbo" element. And I want to make a new function for the clickEvent of "link".

var dialogBox =
{
    description:
    {
        elements:
        [{  
            type: "static_text",
            name: "Text about the link",
        },
        {
            type: "ok",
            item_id: "link",
            ok_name: "Go to Link",
        },
        {
            type: "static_text",
            name: "Some more Information",
        },
        {
            type: "ok",
            item_id: "okbo"
        }]
    },
    commit: function(dialog)
    {
        app.alert("This is triggered by the OK-Button with the ID 'link' \n and I don't know why!");
    }
};
app.execDialog(dialogBox);

If it's impossible to work with different "ok"-Elements in one Dialog I'm open for suggestions on how to get a Hyperlink in my Dialog in a different way!

This is my very first StackOverflow question so please don't kill me :P ;)


Solution

  • See updated code and my comments bellow. For more details about Dialog and execDialog function see here.

    Some of the controls are not documented like:

    •   link_text: a hyper link control
    •   mclv: a multi-column list view (or grid)
    •   slider: a slider 
    •   ok_help, ok_cancel_help, ok_other_help, ok_other_cancel_help controls
    •   separator: draw a line horizontal or vertical with optional caption
    •   Heading and Title fonts about 10pt and 12pt respectively
    •   margin_width, margin_height properties for the view control
    •   back_color, gradient_direction, gradient_type for the view control
    •   A Dialog.setForeColorRed() method
    •   A Dialog.visible() method to show/hide controls
    

    See for more details from this source

    var dialogBox =
        {
            description:
            {
                elements:
                [{      
                    name: "Link to google",         
                    type: "link_text",  // add a hyperlink  
                    item_id: "lnk1",
                    alignment: "align_center",      
                },        
                {  
                    type: "static_text",
                    name: "Text about the link",
                },
                {
                    type: "button",  // add a custom button
                    item_id: "link",
                    name: "Go to Link",
                    alignment: "align_center",
                },
                {
                    type: "static_text",
                    name: "Some more Information",
                },
                {
                    type: "ok",
                    item_id: "okbo"
                }]
            },
                commit: function(dialog)
                {
                    app.alert("okbo!"); //executed only for first ok type
                },
    
                "link": function () // handler of the custom component by id name
                { 
                    xfa.host.gotoURL("http://www.yahoo.com");
                },
    
                "lnk1": function () 
                { 
                    xfa.host.gotoURL("http://www.google.com");
                }
    
        };
        app.execDialog(dialogBox);