jQuery Mobile: Programatically opening a Dialog right after closing another - javascript

I'm currently developing a website that uses jQuery and jQuery Mobile. It has a Login Dialog which contains a Login button and a Register button.
Register
This is the code for the Register button. I'm closing the LoginDialog and opening the RegisterDialog right after inside the "onClick", but what it actually does is close the LoginDialog, then show the RegisterDialog for a quick moment and send me back to the LoginDialog. It does work if I add:
setTimeout(function() {$.mobile.changePage('#RegisterDialog', {role:'dialog', transition:'pop'});}, 100)
Is there any way to fix this problem without this short delay?
I would appreciate any useful answers very much, since I have been trying to find a solution for this problem for quite some time and I can't think of a way to fix it apart from putting a delay between the close and open functions...
EDIT:
The reason why I want to close the Login Dialog before opening the Register Dialog is simply because I want the user to end up on the main page when he or she closes the Register Dialog. So opening a second dialog within the Login Dialog (which I have also tried to do) doesn't solve my problem...
EDIT:
I found a solution to my problem. I just removed the close button from the dialog and added a cancel button at the bottom which just simply does
$.mobile.changePage('#')
That was really all I needed... Sorry for my noobish question :)

You can chain dialogs in jQM. And since you do nothing more in your onClick handlers than just changePage why not just do it all declaratively.
<div data-role="page" data-theme="a" id="home">
<div data-role="header" data-theme="a" align="center">
<h1>Home</h1>
</div>
<div data-role="content">
<p>You need to log in first</p>
<a href="#LoginDialog" data-rel="dialog" data-transition="pop"
data-role="button" data-icon="check" data-inline="true">Login in</a>
</div>
</div>
<div data-role="page" data-theme="d" id="LoginDialog">
<div data-role="header" data-theme="a" align="center">
<h1>Login</h1>
</div>
<div data-role="content">
<p>Provide your login information</p>
<a href="#RegisterDialog" data-rel="dialog" data-transition="pop"
data-role="button" data-icon="check" data-inline="true">Register</a>
</div>
</div>
<div data-role="page" data-theme="e" id="RegisterDialog">
<div data-role="header" data-theme="e" align="center">
<h1>Register</h1>
</div>
<div data-role="content">
<p>Provide your registration information</p>
<a href="#LoginDialog" data-rel="dialog" data-transition="pop"
data-role="button" data-icon="check" data-inline="true">Create an account and retutn to Login</a>
</div>
</div>
Here is jsFiddle

Related

jquery mobile popup dialog: Cannot read property 'is' of undefined

I am trying to open dialog box using jquery. I have followed instruction using link: http://demos.jquerymobile.com/1.2.0/docs/pages/popup/index.html
code looks like:
Dialog
<div data-role="popup" id="popupDialog" data-overlay-theme="a" data-theme="c" style="max-width:400px;" class="ui-corner-all">
<div data-role="header" data-theme="a" class="ui-corner-top">
<h1>Delete Page?</h1>
</div>
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
<h3 class="ui-title">Are you sure you want to delete this page?</h3>
<p>This action cannot be undone.</p>
Cancel
Delete
</div>
</div>
on jquery ready function, trying to open it through code:
$("#popupDialog").popup();
$("#popupDialog").popup("open");
getting error
Not sure what is wrong and can not find any help on this!!!
Open the popup on the jQM pageshow event not the jQuery ready event:
API: http://api.jquerymobile.com/1.3/pageshow/
$(document).on("pageshow","#page1", function(){
$("#popupDialog").popup("open");
});
DEMO

JQuery Mobile Multipage & Appended footer has no styling (Intel XDK)

The multipage is working, but I want to inject the footer code in every page container.
Page Code:
<div data-role="content">
<div class="upage" id="mainpage" data-role="page">
<div class="upage-outer">
<!-- some content -->
</div>
</div>
<div class="upage" id="uberpage" data-role="page">
<div class="upage-outer">
<!-- some content -->
</div>
</div>
</div>
And the I just inject the footer code with some buttons (When device is ready):
$(".upage-outer").append('<div data-role="footer">Copyright + Buttons</div>');
This is the full footer code:
<div data-role="footer" data-position="fixed" class="container-group inner-element uib_w_4" data-uib="jquery_mobile/footer" data-ver="0">
<div data-role="controlgroup" data-type="horizontal" class="brideButtonGroup">
<a class="widget uib_w_6" data-role="button" href="#mainpage" rel="external">Wetter</a>
<a class="widget uib_w_7" data-role="button" onclick="intel.xdk.device.launchExternal('http://wetter2.mt-labor.it.hs-worms.de/plot');">Mehr</a>
<a class="widget uib_w_8" data-role="button" href="#uberpage" rel="external">Über</a>
</div>
</div>
The code gets injected, but on the mainpage, the Buttons are not displayed; instead, there are plain text links. On the second page, everything is displayed very well. I can switch between the pages.
What did I do wrong?
edit: I used enhanceWhithin(), and its working. But when I click somewhere on the document, strange colors appear, which are caused by the class ".ui-fixed-hidden". Where does this come from?
edit2: https://jsfiddle.net/564f1fkf/ It's not exactly the same, but if you go to site 2 and then back to site 1 and click somewhere on the page, you should see the problem.
PS: See pictures
You have to call the enhanceWithin() method on data-role="content" element. This will enhance the newly added HTML into jQuery mobile format.
$("[data-role='content']").enhanceWithin();

Jquery Mobile, not working dialog

I can not see why it is not working this dialog. I am using jqm 1.3
Open dialog
<div id="foo" data-role="dialog">
<div data-role="header" data-theme="d">
<h1>Dialog</h1>
</div>
<div data-role="content">
<h1>Delete page?</h1>
<p>This is a regular page, styled as a dialog. To create a dialog, just link to a normal page and include a transition and <code>data-rel="dialog"</code> attribute.</p>
Sounds good
Cancel
</div>
</div>
I have added on the "head"
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js>
and others jqm events are working.
You need to wrap your anchor tag which invokes the dialog inside a page div as given below.
<div data-role="page">
<div data-role="content">
Open dialog
</div>
</div>
<div id="foo" data-role="dialog">
<div data-role="header" data-theme="d">
<h1>Dialog</h1>
</div>
<div data-role="content">
<h1>Delete page?</h1>
<p>This is a regular page, styled as a dialog. To create a dialog, just link to a normal page and include a transition and <code>data-rel="dialog"</code> attribute.</p>
Sounds good
Cancel
</div>
</div>
You can check out an example at Live fiddle

Reopenning JQM dialog

Hi and happy new year,
There is this JQM dialog, which opens likes this via an AJAX call
$('#calendar-event-form-container').html(HTML).toggle();
$("#calendar-event-form-container").dialog({theme:'a'});
and closes by
$("#calendar-event-form-container").dialog('close');
$("#calendar-event-form-container").toggle();
Next time the dialog is opened it loses its JQM theme and position .
Can anybody see where the code has gone wrong?
Thanks in advance
Sincerely,
Babak
andleer is correct, don't use toggle() with jQM, it is not needed. jQM dialog is created to be used as a separated page. Take a look at this example:
<div data-role="page" id="index">
<div data-theme="a" data-role="header">
<h3>
First Page
</h3>
Next
</div>
<div data-role="content">
Open dialo
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
<!-- DIALOG BOX -->
<div data-role="page" id="dialog-box" data-theme="b">
<div data-role="header">
<h1>Warning</h1>
</div>
<div data-role="content">
<h3 id="dialog-msg">
Dialog test
</h3>
<a href="#" data-role="button" id="close-button">
Close dialog
</a>
</div>
</div>
Also if possible you should open dialog box like this:
$.mobile.changePage('#dialog-box', {transition: 'pop', role: 'dialog'});
In case you are dynamically changing dialogbox content you must trigger pagecreate on it to restyle it correctly:
$('#dialog-box').trigger("pagecreate");
And here's a full jsFiddle example: http://jsfiddle.net/Gajotres/fXzWj/
Showing and Hiding a form as a dialog with toggle() is non-standard. The jQuery Mobile dialog is designed to show or hide a page <div data-role="page"> container. As such, it is assumed to be outside of the current page and won't be visible until displayed as a dialog.
http://jquerymobile.com/demos/1.2.0/docs/pages/dialog/index.html
"Any page can be presented as a modal dialog by adding the data-rel="dialog" attribute to the page anchor link"

Is it safe to remove history.back() function?

On a blackberry browser the history.back(); function redirects the browser back two steps instead (on blackberry browser running OS5.0) of the previous page, in this case #firstpage. So I just remove the call to history.back(); and it works. By works I mean the browser goes to previous page - #firstpage. I'm wondering though if this is correct and im not inadvertently causing unexpected behaviour on a browser I havent tested on. , is it safe to do this across all browsers ?
<div data-role="page" id="firstpage">
<div id="headerItem" data-role="header" data-theme="b">
<h4>Header</h4>
<a data-rel='external' data-ajax="false" href='' class='ui-btn-right' data-icon='home'>Home</a>
</div>
<div data-role="content" data-theme="b" id="links"></div>
<div class="footerDate" data-role="footer" data-theme="b"></div>
</div>
<div id="secondpage" data-role="page" >
<div id="headerDiv" data-role="header" data-theme="b">
Back
<a data-rel='external' data-ajax="false" href='' class='ui-btn-right' data-icon='home'>Home</a>
<h1></h1>
</div>
<div data-role="content" id="pagecontent" ></div>
<div class="footerDate" data-role="footer" data-theme="b"></div>
</div>
I fixed this issue by instead of redirecting when the user clicks the back button, update the page itself using jQuery - set each individual div items data. This is fine for me since there is not much being displayed on the page, but for pages with a large amount of divs and different content it may not be usable.

Categories

Resources