Ever want to detect when the ‘X’ or Escape Key is clicked/pressed to initiate a dialog close - or better yet, disable it completely? Ever want to hook open/close events or run some logic that would stop a dialog from closing in certain situations?
I’ve had this need on many occasions and decided it was time to polish up the custom component I had written. There are many posts in the community regarding this topic so I thought I would share.
Enter, the Popup Controller custom component.
The component hooks the jQuery dialog and its events and invokes snippets that you define when various events occur. It also contains a feature for “hiding the ‘X’” and “disabling the escape key from closing the dialog.” Each popup will have its own Popup Controller so you can vary functionality from popup to popup.
Please note:
- This has not been tested yet in every possible situation (e.g. popups in popups). That said, it should work in all cases and if you do find a problem, please let me know.
- This is written for Skuid 7.x (Banzai) but very minor modifications (builders.js) would be needed to support Skuid 6.x.
To use it:
- Create a new Component pack with a prefix of “myns” and Component Pack Label of “My Namespace Components”
- Upload the zip file from here to replace the default Static Resource created by Skuid for the pack
- Place the Popup Controller Component as the first component on any popup
- Set the Popup Controller component properties as appropriate for your situation
You of course can modify the component pack to fit your specific namespace/module name, etc.
Below is a sample XML page that demonstrates the functionality. To use the sample page, complete steps #1, #2 & #3 from above, then create a new skuid page and copy/paste the XML below.
Feedback, issues, etc. appreciated. Enjoy!
Sample Page XML (uses Account object, standard fields, etc.)
<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true" tabtooverride="Account"> <models>
<model id="Account" limit="100" query="true" createrowifnonefound="false" sobject="Account" adapter="" type="">
<fields>
<field id="Name"/>
<field id="CreatedDate"/>
</fields>
<conditions>
<condition type="param" value="id" field="Id" operator="=" enclosevalueinquotes="true" novaluebehavior="noquery"/>
</conditions>
<actions/>
</model>
</models>
<components>
<pagetitle model="Account" uniqueid="sk-3ro7Me-67">
<maintitle>
<template>{{Model.labelPlural}}</template>
</maintitle>
<subtitle>
<template>Home</template>
</subtitle>
<actions>
<action type="multi" label="Edit in Popup With X" icon="sk-icon-edit">
<actions>
<action type="showPopup">
<popup title="New Popup" width="90%">
<components>
<myns__mynspopupcontroller uniqueid="sk-3roGN_-93" oncreate="onCreateSnippet" onopen="onOpenSnippet" onbeforeclose="onBeforeCloseSnippet" onclose="onCloseSnippet" hideclose="false" disableescape="false"/>
<basicfieldeditor showheader="true" showsavecancel="false" showerrorsinline="true" model="Account" buttonposition="" uniqueid="sk-3royd7-385" mode="read">
<columns>
<column width="100%">
<sections>
<section title="Section A" collapsible="no">
<fields>
<field id="Name"/>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
<pagetitle uniqueid="sk-3rp3OG-403" model="Account">
<actions>
<action type="multi" label="Save" icon="sk-icon-save">
<actions>
<action type="save"/>
</actions>
</action>
<action type="multi" label="Cancel" icon="sk-icon-cancel">
<actions>
<action type="closeTopmostPopup"/>
</actions>
</action>
</actions>
<conditions>
<condition type="contextrow" field="Id" mergefield="Id" operator="="/>
</conditions>
</pagetitle>
</components>
</popup>
</action>
</actions>
</action>
<action type="multi" label="Edit in Popup Without X" icon="sk-icon-edit">
<actions>
<action type="showPopup">
<popup title="New Popup" width="90%">
<components>
<myns__mynspopupcontroller uniqueid="sk-3roGN_-93" oncreate="onCreateSnippet" onopen="onOpenSnippet" onbeforeclose="onBeforeCloseSnippet" onclose="onCloseSnippet" hideclose="true" disableescape="true"/>
<basicfieldeditor showheader="true" showsavecancel="false" showerrorsinline="true" model="Account" buttonposition="" uniqueid="sk-3royd7-385" mode="read">
<columns>
<column width="100%">
<sections>
<section title="Section A" collapsible="no">
<fields>
<field id="Name"/>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
<pagetitle uniqueid="sk-3rp3OG-403" model="Account">
<actions>
<action type="multi" label="Save" icon="sk-icon-save">
<actions>
<action type="save"/>
</actions>
</action>
<action type="multi" label="Cancel" icon="sk-icon-cancel">
<actions>
<action type="closeTopmostPopup"/>
</actions>
</action>
</actions>
<conditions>
<condition type="contextrow" field="Id" mergefield="Id" operator="="/>
</conditions>
</pagetitle>
</components>
</popup>
</action>
</actions>
</action>
</actions>
</pagetitle>
<basicfieldeditor showheader="true" showsavecancel="false" showerrorsinline="true" model="Account" buttonposition="" uniqueid="sk-3uLhmh-94" mode="read">
<columns>
<column width="100%">
<sections>
<section title="Section A" collapsible="no">
<fields>
<field id="Name"/>
<field id="CreatedDate"/>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
</components>
<resources>
<labels/>
<css/>
<javascript>
<jsitem location="inline" name="popupSnippets" cachelocation="false" url="">(function(skuid){
var $ = skuid.$;
skuid.snippet.registerSnippet('onCreateSnippet', function(eventArg) {
window.alert('onCreateSnippet');
});
skuid.snippet.registerSnippet('onOpenSnippet', function(eventArg) {
window.alert('onOpenSnippet');
});
skuid.snippet.registerSnippet('onBeforeCloseSnippet', function(eventArg) {
window.alert('onBeforeCloseSnippet - wasXButton=' + eventArg.wasXButton + ' / wasEscapeKey=' + eventArg.wasEscapeKey);
var prohibitClose = eventArg.wasXButton || eventArg.wasEscapeKey;
// returning false will prohibit close
return !prohibitClose;
});
skuid.snippet.registerSnippet('onCloseSnippet', function(eventArg) {
window.alert('onCloseSnippet');
});
})(skuid);</jsitem>
</javascript>
</resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>