dangerChihuahua007
dangerChihuahua007

Reputation: 20915

Why is my simpledialog2 not working in my jQuery Mobile snippet?

Every time a user clicks on a link in a list view unordered list, a simpledialog2 box should appear. Here is the link to simpledialog2 documentation. It's a popular way to support popboxes in jQuery Mobile applications. http://dev.jtsage.com/jQM-SimpleDialog/demos2/index.html

However, no dialogue box is showing up in my code. Why?

This Fiddle contains my code. http://jsfiddle.net/ykHTa/2/

Here is my HTML.

<ul data-role="listview">
    <li><a href="#">foo</a></li>
    <li><a href="#">bar</a></li>
    <li><a href="#">baz</a></li>
</ul>​

Here is my javascript.

$(function() {

    // When user clicks on a list item, produce a dialogue/alert box.
    $('[data-role="listview"] a').click(function(event) {
        event.preventDefault();
        $('<div>').simpledialog2({
                mode: 'blank',
                headerText: "Popup title",
                headerClose: true,
                blankContent: 
                "My message to you."
        });
    });
});

Upvotes: 1

Views: 3695

Answers (2)

MoGlaNe
MoGlaNe

Reputation: 11

try to replace the call by a function call ?.. I get the same problem and calling a function inside the delegate seem to work ..

$(function() { 
    // When user clicks on a list item, produce a dialogue/alert box. 
    $('[data-role="listview"] a').click(function(event) { 
        event.preventDefault(); 
        fn();
    }); 
}); 

function fn() {
    $('<div>').simpledialog2({ 
        mode: 'blank', 
        headerText: "Popup title", 
        headerClose: true, 
        blankContent:  
        "My message to you." 
    }); 
}

... simpledialog2 ssem to better work within an ajax .success handler ????

Upvotes: 1

shanabus
shanabus

Reputation: 13115

David, your javascript example is missing a closing parenthesis here:

       });
    }); // - close click binding
});

UPDATE

I got it working in your example (jsfiddle) by adding this to your simpledialog2 method call:

dialogForce: true,

Based on documentation here: http://dev.jtsage.com/jQM-SimpleDialog/demos2/dialog.html

Hope this helps!

Upvotes: 2

Related Questions