Jquery Mobile popup triggering by itself - jquery-mobile

I have a popup set up on the index.html as follows:
<!-- Choice Popup -->
<div class="ui-popup-screen ui-overlay-a ui-screen-hidden" id="popupDialog-screen"></div>
<div data-role="popup" class="ui-popup-container ui-overlay-a" data-transition="pop" id="choicePopup">
<div data-role="popup" id="choicePopup" data-overlay-theme="b" data-theme="c" data-dismissible="false" class="ui-corner-all ui-popup ui-body-c ui-overlay-shadow" aria-disabled="false" data-disabled="false" data-shadow="true" data-corners="true" data-transition="slidedown" data-position-to="window" data-arrow="true" data-arrow-sides="t,b,l,r">
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content ui-body-d" role="main">
<h1 class="ui-title" role="heading" aria-level="1">Your decision has been made:</h1>
<h2 align="center" id="choice-p"></h2>
<a href="#" data-role="button" data-inline="true" data-rel="back" data-theme="c" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" class="ui-btn ui-btn-up-c ui-shadow ui-btn-corner-all ui-btn-inline">
<span class="ui-btn-inner">
<span class="ui-btn-text">Thanks</span>
</span>
</a>
<a href="#" onclick="eatsome('Food'); return false;" data-role="button" data-inline="true" data-transition="flow" data-theme="b" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" class="ui-btn ui-btn-up-b ui-shadow ui-btn-corner-all ui-btn-inline">
<span class="ui-btn-inner">
<span class="ui-btn-text">Again!</span>
</span>
</a>
</div>
</div>
The problem is, I don't know why its booting on loading, some attribute is triggering it, can anyone find the issue? Thank you

There are several issues with your markup and code:
First of all your markup for the popup looks already jQM-enhanced like being copied from the browser's developer view. Therefore make it normal first. It might look like
<div data-role="popup" id="choicePopup" data-overlay-theme="b" data-theme="c" data-dismissible="false" class="ui-corner-all">
<div data-role="header" data-theme="a" class="ui-corner-top">
<h1></h1>
</div>
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
<h3 class="ui-title">Your decision has been made:</h3>
<a id="btnThanks" href="#" data-role="button" data-inline="true" data-rel="back" data-theme="c">Thanks</a>
<a id="btnAgain" href="#" data-role="button" data-inline="true" data-rel="back" data-transition="flow" data-theme="b">Again!</a>
</div>
</div>
Second a popup markup should reside inside the same page as the link that opens it.
<div data-role="page" id="main">
...
<div data-role="popup" id="choicePopup">
...
</div>
</div>
Third use proper jQM events to place your code that manipulates the content.
Forth Stop using onclick and other on* event attributes with jQM. Once again use proper jQM or jQuery events.
So instead of
<a href="#" onclick="eatsome('Food'); return false;" ... >Again!</a>
use
<a id="#btnAgain" href="#" ... >Again!</a>
$("#btnAgain").click(function(){
eatsome('Food');
return false;
});
Fifth After injecting html you need to call trigger('create') on a parent element to let jQM enhance and style the markup that you injected.
var content = '<form>;
...
content += '</form>;
$("div.settings-content").html(content).trigger("create");
And here is working jsFiddle based on your markup. As you can see the popup doesn't pop up on its own. There are two buttons that show how to open the popup declaratively and programmatically. And content for settings page is injected and styled properly.

Related

jQM v1.4.0.RC.1 and popups

I am having a problem with nested popups with v1.4.0.RC.1. It works in v1.3.2. I have a footer, which has a button, which opens a popup, which contains a listview, and one of the listitems opens a popup. Again, in v1.3.2, this works as expected... but not with v1.4.0.RC.1. I understand that v1.4 isn't out yet, but I pose this issue anyway as someone may have some insight that I haven't come up with yet. I have a fiddle for both versions. The code for each is exactly the same. The only difference is that the first fiddle uses the 1.3.2 libraries and the second fiddle uses the v1.4.0 libraries.
Also, I have seen answers linking to a jQM popup page, showing that the page itself indicates that chaining popups isn't allowed. However, that's typically a v1.2.0 of jQM. The popup demo in v1.3.2 doesn't indicate that restriction, and is supported by the fact that it does in fact work (see fiddle below).
That being said, if anybody has any guidance or information, I'd really appreciate it. I've poured through the limited 1.4.0 documentation and the interwebs and the only thing I can come up with is doing a setTimeout within the popupafterclose event to open another popup. That seems like a sloppy hack to me, and I'd like to avoid doing that if at all possible.
Anyway, below is code and fiddles for 1.3.2 and 1.4.0.RC.1.
Thanks!
<div data-role="page" id="pgMain">
<!-- HEADER -->
<div id="hdrMain" data-role="header">
<h1>Popups from popups using jQM-1.3.2</h1>
</div>
<!-- CONTENT -->
<div data-role="content" id="contMain">
With jQM-1.3.2, the menu button down there opens a popup window as a menu. In the popup window is a listview, and the "Delete" listitem calls another popup to confirm deletion.<br/><br/>With jQM-1.4.0.RC.1, the second popup doesn't work.
</div>
<!-- FOOTER -->
<div id="ftrMain" data-role="footer" data-position="fixed" data-tap-toggle="false">
<div class="ui-btn-inline ui-shadow" style="margin-left:5px; margin-right:2px;" data-role="controlgroup" data-type="horizontal" data-mini="true">
Menu <--- Click this...
</div>
</div>
<!-- POPUP: SELECTED ITEMS MENU -->
<div id="mnuSelectedItemsMenu" data-role="popup">
<ul id="lvItemMenu" style="min-width: 210px;" data-role="listview" data-inset="true" data-icon="">
<li>Edit</li>
<li>Delete <--- ...then this</li>
<li data-role="list-divider" style="padding:2px 0px 0px 0px;"></li>
<li>Select All</li>
</ul>
</div>
<!-- POPUP: CONFIRM DELETE DIALOG -->
<div id="popupConfirmDelete" class="ui-corner-all" data-role="popup" data-overlay-theme="a" data-dismissible="false">
<div class="ui-corner-top" data-role="header">
<h1>Delete Transaction</h1>
</div>
<div class="ui-corner-bottom ui-content" data-role="content" >
<h3 class="ui-title">Are you sure you want to delete these transactions?</h3>
<p>This action cannot be undone!</p>
<div class="ui-grid-a point6em" style="margin-top:10px;">
<div class="ui-block-a">
<a id="btnDoDeleteTransactions" data-role="button" data-mini="true">Delete</a>
</div>
<div class="ui-block-b point6em">
<a data-role="button" data-rel="back" data-mini="true">Cancel</a>
</div>
</div>
</div>
</div>
fiddle for v1.3.2 above
<div data-role="page" id="pgMain">
<!-- HEADER -->
<div id="hdrMain" data-role="header">
<h1>Popups from popups using jQM-1.4.0.RC.1</h1>
</div>
<!-- CONTENT -->
<div data-role="content" id="contMain">
With jQM-1.3.2, the menu button down there opens a popup window as a menu. In the popup window is a listview, and the "Delete" listitem calls another popup to confirm deletion.<br/><br/>With jQM-1.4.0.RC.1, the second popup doesn't work.
</div>
<!-- FOOTER -->
<div id="ftrMain" data-role="footer" data-position="fixed" data-tap-toggle="false">
<div class="ui-btn-inline ui-shadow" style="margin-left:5px; margin-right:2px;" data-role="controlgroup" data-type="horizontal" data-mini="true">
Menu <--- Click this...
</div>
</div>
<!-- POPUP: SELECTED ITEMS MENU -->
<div id="mnuSelectedItemsMenu" data-role="popup">
<ul id="lvItemMenu" style="min-width: 210px;" data-role="listview" data-inset="true" data-icon="">
<li>Edit</li>
<li>Delete <--- ...then this</li>
<li data-role="list-divider" style="padding:2px 0px 0px 0px;"></li>
<li>Select All</li>
</ul>
</div>
<!-- POPUP: CONFIRM DELETE DIALOG -->
<div id="popupConfirmDelete" class="ui-corner-all" data-role="popup" data-overlay-theme="a" data-dismissible="false">
<div class="ui-corner-top" data-role="header">
<h1>Delete Transaction</h1>
</div>
<div class="ui-corner-bottom ui-content" data-role="content" >
<h3 class="ui-title">Are you sure you want to delete these transactions?</h3>
<p>This action cannot be undone!</p>
<div class="ui-grid-a point6em" style="margin-top:10px;">
<div class="ui-block-a">
<a id="btnDoDeleteTransactions" data-role="button" data-mini="true">Delete</a>
</div>
<div class="ui-block-b point6em">
<a data-role="button" data-rel="back" data-mini="true">Cancel</a>
</div>
</div>
</div>
</div>
fiddle for v1.4.0.RC.1 above

jQuery Mobile custom select not closing

I have a web application which uses jQuery 1.6.2 and jQuery Mobile 1.0b3. I need to display a list of options, so I used a custom select. I cannot close the select by using the header button, and neither by selecting an option.
The nativeMenu = false is set globally.
I create the select using
<select data-mini="true">
<option value="1">Option1</option>
<option value="2">Option2</option>
</select>
The HTML look like this (there are many more options, so the select goes full-screen):
<div data-role="dialog" data-theme="c" data-overlay-theme="a" tabindex="0"
class="ui-page ui-body-c ui-dialog ui-overlay-a ui-page-active" style="min-height: 480px;">
<div role="dialog" class="ui-dialog-contain ui-corner-all ui-overlay-shadow">
<div data-role="header" class="ui-corner-top ui-header ui-bar-a" role="banner">
<a href="#" data-icon="delete" data-iconpos="notext"
class="ui-btn-left ui-btn ui-shadow ui-btn-corner-all ui-btn-icon-notext ui-btn-up-a" data-corners="true"
data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a" title="Close">
<span class="ui-btn-inner ui-btn-corner-all">
<span class="ui-btn-text">Close</span>
<span class="ui-icon ui-icon-delete ui-icon-shadow"> </span>
</span>
</a>
<div class="ui-title"></div>
</div>
<div data-role="content" class="ui-corner-bottom ui-content ui-body-c" role="main">
<ul class="ui-selectmenu-list ui-listview" id="undefined-menu" role="listbox" aria-labelledby="undefined-button"
data-theme="c">
<li data-option-index="0" data-icon="false" class="ui-btn ui-btn-icon-right ui-li ui-btn-active ui-btn-up-c"
role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div"
data-iconpos="right" data-theme="c" aria-selected="true">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
Option1
</div>
</div>
</li>
<li data-option-index="1" data-icon="false" class="ui-btn ui-btn-icon-right ui-li ui-btn-up-c" role="option"
data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right"
data-theme="c" aria-selected="false">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
Option2
</div>
</div>
</li>
</div>
</div>
</div>
The header button works with jQuery 1.8.3 & jQm 1.2.1 (selecting an option still doesn't work), but changing this versions leads to other problems in my legacy app, so I would prefer a solution for 1.6.2 & jQm 1.0.
Any ideas why the select doesn't work ?
EDIT:
After a couple of days of searching, I found out that the dialog doesn't close because I have set hashListeningEnabled = false. Unfortunately, I cannot change this. I stumbled upon this: https://github.com/jquery/jquery-mobile/issues/2285, but I cannot upgrade the jQm/jQuery version. So I'm left with finding some good alternative for the select. Any suggestions ?
wow... no answer to this... almost one year bfore! and i have the same (or actually similar... soon enough) issue. So here i go with my experience:
(in which i need to mention that i am able to select multiple items but when i hit the cross button over the header... no closing action will follow. so DANG!
i have been trying to figure some kind of workaround for this.. so i started mutating some other jQm pop ups and the problem that i'm facing now is that my solution seems to show different buttons with the html object (each time you click this one only button it goes round the SELECT's items displaying them one at a time inside this one button, very weird... at least for my rookie experience with jquery mobile, so maybe its a simple couple of options that i didnt kneew how to set, but im being blind to the solution.
So, what do i need to show a nice popup like the one in the picture (also code pasted below) from a common SELECT (HTML OBJECT) ?
(please take a look of what i intent to achive (the look and feel)
h t t p : / / i . s t a c k . i m g u r . c o m /I5q0I.png
And this is the code that i should have (but with the cross working, which is not.)
<div class="ui-popup-container ui-popup-active" id="select-choice-7458-listbox-popup" tabindex="0" style="max-width: 1825px; top: 2788.5px; left: 805.5px;">
<div id="select-choice-7458-listbox" class="ui-selectmenu ui-popup ui-body-a ui-overlay-shadow ui-corner-all">
<div class="ui-header ui-bar-c">
<h1 class="ui-title">
</h1>
<a href="#" class="ui-btn-left ui-btn ui-btn-up-c ui-shadow ui-btn-corner-all ui-btn-icon-notext" data-iconpos="notext" data-icon="delete" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c" title="Close">
<span class="ui-btn-inner">
<span class="ui-btn-text">
Close
</span>
<span class="ui-icon ui-icon-delete ui-icon-shadow">
</span>
</span>
</a>
</div>
<ul class="ui-selectmenu-list ui-listview" id="select-choice-7458-menu" role="listbox" aria-labelledby="select-choice-7458-button" data-theme="c" data-divider-theme="b">
<li data-option-index="0" data-icon="checkbox-off" data-placeholder="true" class="ui-selectmenu-placeholder ui-btn ui-btn-up-c ui-btn-icon-right ui-li-has-arrow ui-li ui-first-child" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="c" aria-selected="false">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
</div>
<span class="ui-icon ui-icon-checkbox-off ui-icon-shadow">
</span>
</div>
</li>
<li data-option-index="1" data-icon="checkbox-off" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="c" aria-selected="false">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
<a href="#" tabindex="-1" class="ui-link-inherit">
Scribbling</a>
</div>
<span class="ui-icon ui-icon-checkbox-off ui-icon-shadow">
</span>
</div>
</li>
<li data-option-index="2" data-icon="checkbox-off" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="c" aria-selected="false">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
<a href="#" tabindex="-1" class="ui-link-inherit">
Letter-like symbols</a>
</div>
<span class="ui-icon ui-icon-checkbox-off ui-icon-shadow">
</span>
</div>
</li>
<li data-option-index="3" data-icon="checkbox-off" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="c" aria-selected="false">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
<a href="#" tabindex="-1" class="ui-link-inherit">
Strings of letters</a>
</div>
<span class="ui-icon ui-icon-checkbox-off ui-icon-shadow">
</span>
</div>
</li>
<li data-option-index="4" data-icon="checkbox-off" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="c" aria-selected="false">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
<a href="#" tabindex="-1" class="ui-link-inherit">
Beginning sounds
</a>
</div>
<span class="ui-icon ui-icon-checkbox-off ui-icon-shadow">
</span>
</div>
</li>
<li data-option-index="5" data-icon="checkbox-off" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="c" aria-selected="false">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
<a href="#" tabindex="-1" class="ui-link-inherit">
Ending and medial sounds
</a>
</div>
<span class="ui-icon ui-icon-checkbox-off ui-icon-shadow">
</span>
</div>
</li>
<li data-option-index="6" data-icon="checkbox-off" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-last-child ui-btn-up-c" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="c" aria-selected="false">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
<a href="#" tabindex="-1" class="ui-link-inherit">
Conventional writing
</a>
</div>
<span class="ui-icon ui-icon-checkbox-off ui-icon-shadow">
</span>
</div>
</li>
</ul>
</div>
</div>

JQuery Mobile Page Not Refreshing

I Did do my home work but i cannot get it to work.The Button Styles Are Not Refreshing Please Help.
<div id="qpage" data-role="page">
<div data-role="header">
<a id="exit-quiz" data-role="button" data-icon="arrow-l" >Exit</a>
<h1 id="ques-title">#ques-title</h1></div>
<div data-role="content">
<div class="ui-bar-a" id="ques-timer">
#ques-timer
</div>
<div id="question"><h3>#Question</h3></div>
<div class=".button-set" data-role="controlgroup" id="answerbox">
<a data-role="button" id="answer_1">#answer_1</a>
<a data-role="button" id="answer_2">#answer_2</a>
<a data-role="button" id="answer_3">#answer_3</a>
<a data-role="button" id="answer_4">#answer_4</a>
</div>
<div id="explanation">
</div>
</div>
<div data-role="footer"><h2>Copyright Kaveen</h2></div>
</div>
This is Th Javascript I wrote
$("#subject1").bind('click',function(){
var json = $.get("test.json",function(data){
$("#question").html(data.question);
$("#answer_1").html(data.mcq_1);
$("#answer_2").html(data.mcq_2);
$("#answer_3").html(data.mcq_3);
$("#answer_4").html(data.mcq_4);
});
i did try $( "div[data-role=page]" ).page( "destroy" ).page(); But it wont work Plese Help Me Thank you. JSFIDDLE http://jsfiddle.net/xRTCu/
Try this, it should work:
$("#answer_1").button("refresh");
If that is also not working, try this
$("#answer_1").buttonMarkup();
EDIT: jsfiddle updated http://jsfiddle.net/androdify/xRTCu/4/
Use this:
$("#answer_1 .ui-btn-text").text(data.mcq_1);
Why? Because jquery mobile adds a span around the button which has class="ui-btn-text"
Try $( "div[data-role=page]" ).trigger ("create") if you're using the latest version of jQuery mobile. page was deprecated some versions ago.
If you're using an older version of jQM, then you could use $("[data-role=button]").button().button ("refresh") after you're done appending your JSON data into those buttons.
EDIT
From your fiddle I can see that you're using html() and that's erasing jQM's markup. This is what data-role=button converts your markup:
<a data-role="button" id="answer_1">#answer_1</a>
//becomes
<a data-role="button" id="answer_1" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c" class="ui-btn ui-shadow ui-btn-corner-all ui-first-child ui-btn-up-c">
<span class="ui-btn-inner">
<span class="ui-btn-text">mcq wrong</span>
</span>
</a>
So by using html() youre effectively erasing everything inside a. Try searching for ui-btn-text class inside a like this and then run html with your text in it:
$(".ui-btn-text", "#answer_1").html(data.mcq_1);
//OR
$("#answer_1").find(".ui-btn-text").html(data.mcq_1);
Here's your updated demo : http://jsfiddle.net/hungerpain/xRTCu/3/

Jquery Mobile - nested list items using same href

I have a list I am creating dynamically. The content looks good BUT each link points to the same page link:
I start with an empty list:
<div data-role="content" class="ui-content" role="main">
<ul data-role="listview" data-theme="b" data-inset="true" id="profile2" class="ui-listview ui-listview-inset ui-corner-all ui-shadow">
</ul>
</div>
I use $('#profile2').append to build the list and use $('#profile2').listview("refresh"); to refresh the list after each new link is inserted.
Here is a sample of code after the list has been generated:
<div data-role="content" class="ui-content" role="main">
<ul data-role="listview" data-theme="b" data-inset="true" id="profile2" class="ui-listview ui-listview-inset ui-corner-all ui-shadow">
<li><div class="ui-btn-inner ui-li">
<div class="ui-btn-text"><a href="#/demo?a=53&b=-7&ui-page=profile2-0" class="ui-link-inherit">
<h3 class="ui-li-heading">Headin1</h3>
<p class="ui-li-desc">Content 1</p></a><
</div>
<span class="ui-icon ui-icon-arrow-r ui-icon-shadow"> </span></div>
</li>
<li><div class="ui-btn-inner ui-li">
<div class="ui-btn-text"><a href="#/demo?a=53&b=-7&ui-page=profile2-0" class="ui-link-inherit">
<h3 class="ui-li-heading">Headin2</h3>
<p class="ui-li-desc">Content 2</p></a><
</div>
<span class="ui-icon ui-icon-arrow-r ui-icon-shadow"> </span></div>
</li>
</ul>
</div>
NOTE the href for both links refers to profile2-0
Interestingly, the pages generated for the child links have the same tabindex (0), as well as the same data-url. This is the code for both pages:
<div data-role="page" data-url="/demo?a=53&b=-7&ui-page=profile2-0" tabindex="0" class="ui-page ui-body-a">
CONTENT.....
</div>
I use listview("refresh") to refresh the styling, should this also take care of ensuring the page items are uniquely labeled?
Of course, this should be taken care of by JQM, but I cannot see a way to programmatically set a sub page link when creating the list item to ensure the links are unique.
As it has already been pointed out by Taifun, you probably have a problem in the code generating the list items (that you did not provide).
I tried this code, and did not face any issue:
<script>
$(document).on("pageshow", function(){
for(i=0; i<10; i++) {
$("#profile2").append('<li>test ' + i + '</li>');
}
$("#profile2").listview('refresh');
});
</script>
Hope that helps.

jquery-mobile: Collapsible inside list-view

I want to use some collapsible elements inside a listview in jquery mobile. I can set well the collapsible adding a inside the corresponding part, but when the collapsible is not collapsed, the info of collapsible is not inside the collapsible bubble, how can I fix that to have a bubble that include title and description?
Thanks
<div id="dispositivo" data-role="page" data-theme="c" data-cache="refresh">
<div data-role="content" role="main">
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
<li data-role='list-divider'>Titulo</li>
<form id="form_disp" name="form_disp" method="post" action="test.php">
<li data-role='fieldcontain'>
<a id="estado" name="estado" href="#" data-theme="b" data-role="button" data-inline="true">Boton</a>
<div data-role="content" data-inset="true">
<div data-role="collapsible" data-inset="true">
<h3>Info1</h3>
<p>Ahora estamos viendo el info 1</p>
</div>
<div data-role="collapsible">
<h3>Info 2</h3>
<p>Ahora estamos viendo el info 2</p>
</div>
</div>
<button data-theme="b" id="b_conf_disp" data-role="button" data-inline="true" type="submit">Boton 2</button>
</form>
</ul>
</div>
</div>
I think you missed </li> tag.
For something similar you can try using the plugin I wrote that allows certain listview items to be opened inline within the listview.
The Github Repo

Resources