jquery-mobilejquery-mobile-popup

Popup not working within jquerymobile


I'm a touch lost - I have taken a popup example from the jquery demo page as a template...

If I put my popup within the first page, it works - I can call it from within js script to open.

Thus... the following does work

    <div data-role="page" class="page" id="Menu">
    <div data-role="header" data-position="fixed" class="ui-title center">
        <div data-role="controlgroup" data-type="horizontal">
            <a href="#" class="ui-btn ui-corner-all ui-icon-user ui-btn-icon-notext">&nbsp;</a>
            <a href="#OrderList" class="ui-btn ui-corner-all width150 htitle OrderList">&nbsp;<span class='htitle'>Barserver.com</span>&nbsp;</a>
            <a href="#" class="ui-btn ui-corner-all ui-icon-gear ui-btn-icon-notext">&nbsp;</a>
        </div>
    </div>
    <div id="MainContent">
        <div id="MenuList"></div>    
    </div>
<div data-role="popup" id="popup" data-overlay-theme="b" data-theme="b" data-dismissible="false" style="max-width:400px;">
        <div data-role="header" data-theme="a">
        <h1>Delete Page?</h1>
        </div>
        <div role="main" class="ui-content">
            <h3 class="ui-title">Are you sure you want to delete this page?</h3>
        <p>This action cannot be undone.</p>
            <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back">Cancel</a>
            <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back" data-transition="flow">Delete</a>
        </div>
</div>

I can dynamically open it via

$("#popup").popup("open");

However if I move the popup to another (data-role) page within the same document, it does not get displayed, nor errors in console.log. Can anyone steer me forward? The following does NOT work...

<div data-role="page" class="page" id="OrderList">
    <div data-role="header" data-position="fixed" class="ui-title text-center">
        <div data-role="controlgroup" data-type="horizontal">
            <a href="#Menu" class="ui-btn ui-corner-all ui-icon-carat-l ui-btn-icon-notext Menu">&nbsp;</a>
            <a href="#Menu" class="ui-btn ui-corner-all width150 htitle Menu">&nbsp;<span class='htitle'>Barserver.com</span>&nbsp;</a>
            <a href="#Customer" class="ui-btn ui-corner-all ui-icon-carat-r ui-btn-icon-notext">&nbsp;</a>
        </div>
    </div>
    <div id="OrderListContent" class="productdhtml ui-content"></div>
<div data-role="popup" id="popup" data-overlay-theme="b" data-theme="b" data-dismissible="false" style="max-width:400px;">
            <div data-role="header" data-theme="a">
            <h1>Delete Page?</h1>
            </div>
            <div role="main" class="ui-content">
                <h3 class="ui-title">Are you sure you want to delete this page?</h3>
            <p>This action cannot be undone.</p>
                <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back">Cancel</a>
                <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back" data-transition="flow">Delete</a>
            </div>
    </div>
        </div>

To avoid misunderstanding - the first code sample works, the second one does not work (meaning no errors, no modal like dialog box gets displayed).

Why?

(All help appreciated of course)


Solution

  • I got it (thanks to @Omar for direction). A coded answer is not easy but I will try draft and share in a few days (I'm behind on my work because of trying to fix this problem).

    For the purpose of this note, when I say "this failed" I mean "no popup, no change in address bar, no console error."

    I have a form. If operator attempted to navigate away, a test should be done to confirm all data was entered. All my a-href tags had page references, and jquery gives precedence to a-href tags over any other events I had applied. I had not considered the ramifications of this. The result? Form displayed, incompletely filled, operator selects to navigate elsewhere, popup call starts/ends but "failed" and jquery quickly navigates to the page named in the a-href page.

    Solution: When using popups, do not name pages in a-href tags. Thus, when using popups, avoid

    <a href='#Page5'>Page 5</a>
    

    and instead

    <a href='#' id='page5'>Page 5</a>
    

    and create an event that decides if a popup should be displayed, or if not, that page5 should be navigated to.

    I hope that makes sense.