Since JQM 1.4 has changed some widgets, in order to use "dialog" widget, there are 2 options:
- data-role="page" data-dialog="true"
- data-rel="popup"
I'm using first approach, so when user clicks "OK" button of my dialog, I update database and if all is ok, I would like to close the dialog.
As mentioned in JQM doc I've tried using $( ".selector" ).dialog( "close" )
but it throws Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'
. Some example code:
Dialog HTML
<div id="manage-page" data-role="page" data-dialog="true" data-corners="false" data-close-btn="right" data-overlay-theme="b">
<div data-role="header">
<h1>Manage</h1>
</div>
<div data-role="content">
<h3>Title</h3>
<input type="text" id="title" value=""/>
<a href="#" id="saveTitle" data-role="button">Save</a>
</div>
</div>
Dialog JS
$(document).on('click', '#saveTitle', function(){
var title= $('#title').val();
$.ajax({
type: "POST",
url: CUSTOM_URL,
success: function(data) {
if(data != -1)
$('#manage-page').dialog('close');
else
// Some stuff
},
error: function() {
console.log("ERROR saving title");
}
});
});
What is wrong? Thanks
UPDATE
I've solved using data-rel="back"
in my open button and removing $('#manage-page').dialog('close');