Search code examples
jqueryjquery-mobilecordovasimpledialog

typeerror result of expression $(this).simpledialog [undefined] is not a function


I am following the http://dev.jtsage.com/jQM-SimpleDialog/demos/string.html link for creating the dialog using jquery mobile i have defined the following in my html

 <div data-role="popup" id="Savepopup" class="ui-corner-all" style="background: url(Image/PopupBackground.png); background-size: 100% 100%;background-repeat: no-repeat;">
    <div id="datalink">
        <a href="#" data-inline="true" data-rel="dialog" ><img src="Image/Button.png" width="100%" height="" ></a>
    </div>
    </div>

and in js file i have defined the following



 $(document).delegate('#datalink', 'click', function() {
    $(this).simpledialog({
    'mode' : 'string',
    'prompt' : 'What do you say?',
    'buttons' : {
      'OK': {
        click: function () {
         // var name = text($('#datalink').attr('data-string'));
          //console.log("name name "+name);
          alert("data was entered");
        }
      },
      'Cancel': {
        click: function () { },
        icon: "delete",
        theme: "c"
      }
    }
  });
});

but when i click on the button to open dialog i get the error saying $(this).simpledialog is not a function. What's the mistake i am doing?..


Solution

  • I hope you have initialized jQM-SimpleDialog js file because this is a 3rd party dialog implementation, and it cant be found inside a classic jQuery Mobile framework.

    If you only need to use basic dialog then I would advise you to use normal jQM dialog.

    Basically your error is saying that simpledialog function can't be found and that is because it is not initialized.

    I made you a working example for classic jQM dialog :http://jsfiddle.net/Gajotres/Jx9xM/

    $(document).on('pageinit', '#mainPage', function(){ 
        $(document).on ('click','#createEvent', function () {        
            $.mobile.changePage('#addCatForm', {
                transition: 'pop',
                changeHash: true,
                role: 'dialog'
            });
        });
    
        $(document).on('click','#canCat',function () {
            $('#addCatForm').dialog('close');
        });        
    });