I have a jQuery Mobile pop-up box like so (see code below), and need to add a dialog box to each option that prompts “Are you sure?” OK or Cancel:
(Note: I temporarily removed all options except the first to make the code cleaner)
<!--- Status, Suspend, Restore, Disconnect popup dialog box --->
<div data-role="popup" id="popupStatus" data-overlay-theme="a" data-theme="c"
style="max-width:500px;" class="ui-corner-all">
<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<div data-role="header" data-theme="a" class="ui-corner-top">
<h1>Status</h1>
</div>
<div data-role="content" data-theme="d"
class="ui-corner-bottom ui-content" data-backbtn="false">
<h3 class="ui-title">Choose an Action:</h3>
<a href="edit_ttStatus.cfm?id=<cfoutput>#rsTicketDetail.ttNum#</cfoutput>&id1=<cfoutput>#rsTicketDetail.sta#</cfoutput>" class="ui-corner-all" data-role="button" data-inline="false" data-transition="flow" data-theme="b">Change</a>
</div>
</div>
Here is the code for the Dialog, but I’m not sure how to “integrate” it with the above code:
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
<h3 class="ui-title">Are you sure?</h3>
<p>This action will ________ the ticket.</p>
<a href="#" class="ui-corner-all" data-role="button" data-inline="true" data-rel="back" data-theme="c">Cancel</a>
<a href="#" class="ui-corner-all" data-role="button" data-inline="true" data-transition="flow" data-theme="b">OK</a>
</div>
You can try the solution below.
Note that a full working example (code + screenshots) is provided in the end of the post…
1 – Add a class (eg:
myopt) to all your option inside your pop-up box#popupStatus.Example with 2 more options (
ValidateandCancel):2 – Define an ID attribute (eg:
#popup_option) for your pop-up which will prompt the messageAre you sure?, and include a<span>tag (eg:<span id="myoption"></span>) which will contain the dynamic message you want to “integrate” (according to the option you select from the pop-up#popupStatus):3 – Define the following click event function for the options of your pop-up box
#popupStatus:The function above does the following:
It first takes the index of the option that is clicked, in the pop-up box
#popupStatus, and store it in the variableind.indwill equals1,2, or3if the optionChange,Validate, orCancelis clicked (respectively).The variable
tosetis the content that we want to “integrate” dynamically inside the pop-up box#popup_option, depending on the option we previously clicked in the pop-up#popupStatus. It is initially set to"".From the
switchstatement, in the code, we set the value of the variabletosettochange,validate, orcancel, depending on the option we selected from the pop-up#popupStatus.We include the value / content of
tosetinside the<span>tag that is inside the pop-up#popup_optionwith$("#myoption").html(toset);We close the pop-up
#popupStatusand open#popup_optionwhich contains the dynamically generated message (change,validate, orcancel).We notice that we need to open the pop-up box
#popup_optionusing thesetTimeoutfunction. You cannot directly open it using$( '#popup_option' ).popup( 'open', { transition: "flow" } );, because chaining of pop-ups is not allowed.You can check the online doc which mentions the following:
Full example:
Screenshots of testing:
Opening the page:
After clicking on the button shown above:
After selecting the option
Validate:Hope this helps. Let me know if you have any questions :).