Jump to content
  • Spotfire Confirmation Dialog before Script Execution


    This article explains how to set up a confirmation dialog in Spotfire using HTML and JavaScript. The code provided ensures that a confirmation prompt appears before executing an action like a data function or script, enhancing user interaction and preventing unintended execution of actions.

    This code provides a user-friendly way to confirm actions in Spotfire, preventing accidental executions and enhancing the user experience. The confirmation dialog ensures that users are certain before proceeding with the execution, while the friendly message upon cancellation maintains a positive interaction.

     

    confirm.gif.e897a7429ff091f212d93b56d3c53af5.gif

     

    html
     

    <div id="confirmExecute">
       <SpotfireControl id="replace with Spotfire Action Control button" />
    </div>
    
    <div id="actualExecute" style="position:fixed;top:-100px">
       <SpotfireControl id="replace with Spotfire Action Control button" />
    </div>
    • confirmExecute: This <div> contains the Spotfire control that will display a confirmation dialog when interacted with. It triggers an IronPython script that does nothing (the script is empty, it's just a placeholder). The JavaScript takes cares of the popup confirmation dialog.
    • actualExecute: This <div> contains the Spotfire control that performs the actual execution. It is positioned off-screen using the CSS position:fixed;top:-100px style to keep it hidden. It is linked to the actual IronPython, DataFunction or any other element the Spotfire Action Control can handle.

    JavaScript

    // Setup the first Spotfire control button (that does nothing) to show a confirm dialog
    document.querySelector("#confirmExecute input").onclick = function() {
       Spotfire.ConfirmDialog.showYesNoCancelDialog("Confirm Execution", "Do you really want to execute?", okClick, noClick, null);
    }
    
    // Programmatically click on Spotfire control when confirming
    okClick = function(x) {
       document.querySelector("#actualExecute input").click();
    }
    
    // Display a friendly message if the user cancels
    noClick = function(x) {
       Spotfire.ConfirmDialog.showDialog("OK", "No worries!", []);
    }

    The first Spotfire control (#confirmExecute) is set up to show a confirmation dialog when clicked. The dialog has "Yes", "No", and "Cancel" options, triggering the corresponding functions: okClick for "Yes" and noClick for "No".

    The okClick Function: If the user confirms the execution by clicking "Yes", the okClick function is called, which programmatically clicks the hidden Spotfire control in the #actualExecute <div>, triggering the actual execution. The noClick Function: If the user clicks "No", the noClick function displays a friendly message dialog using Spotfire.ConfirmDialog.showDialog.

    Important Note:  the Spotfire.ConfirmDialog.showDialog is not a public API that can change at any time and might not work on future versions of Spotfire. This is just to illustrate the concept. You could also use the confirm dialog instead or create your own confirmation dialog. 


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...