jQuery Mobile - Popup in nested list view - jquery-mobile

I try to create a listview where elements with no children can have an edit button. When the user clicks to this button a popup menu should appear.
Here is the code inside a singe JQM page.
<div data-role="content">
<ul data-role="listview">
<li>
<h3>Colors</h3>
<ul>
<li>Blue
<p class="edit">
<a href="#" onclick="openEditMenu()" data-role="button"
data-icon="gear" data-inline="true" data-iconpos="notext">Edit</a>
</p>
</li>
<li>Orange</li>
<li>Purple</li>
</ul>
</li>
<li><h3>Item</h3>
<p class="edit">
<a href="#" onclick="openEditMenu()" data-role="button"
data-icon="gear" data-inline="true" data-iconpos="notext">Edit</a>
</p></li>
</ul>
</div>
<div data-role="popup" id="popupMenu">
<ul data-role="listview" data-inset="true" >
<li data-role="divider" data-theme="a">Edit Element</li>
<li>Edit</li>
...
</ul>
</div>
<script>
function openEditMenu() {
$('#popupMenu').popup('open');
}
</script>
On the first level this works like expected. If you navigate to the second level of the nested list, the popup is not shown.
I saw that popups in JQM has to be placed on the same page. It seems that JQM does not find the popup on the subpages of the listview.
Has somebody realized successfully such a solution or it is not possible with the popup feature of JQM 1.2?
On jsfiddle you can find my example code.
Thanks for tipps or suggestions.

As you said in the comments above, from the jQm documentation 'A popup div has to be nested inside the same page as the link.'.
What you could try is clone the popup and attach it to the other page. Then you have re-initialize and open it.
You could try something like:
var nestedLiPage = $(".ui-page-active");
$('#popupMenu').clone().appendTo(nestedLiPage).popup().popup('open');

[Solved]
http://jsfiddle.net/F9awk/
function openEditMenu() {
var nestedLiPage = $(".ui-page-active");
$('#popupMenu').clone().appendTo(nestedLiPage).popup().popup('open');
}

Related

Kendo UI Mobile - How to display 2 listview on a view?

I want to show a view with 2 listview like this:
But when I implement by Kendo UI Mobile with:
<div id="cptTab" data-role="view" data-title="Billing" data-layout="billing-layout">
<header data-role="header">
<div data-role="navbar">
<span data-role="view-title">CPT</span>
<a data-align="left" data-role="button" href="#censusmainTab">Census</a>
<a data-align="right" data-role="button" data-click="onNavigateToAddCpt">+</a>
</div>
</header>
<div>
Patient:
<label>
<input readonly="true" class="PatientNameLabel" />
</label>
</div>
<div>NEW CPT's</div>
<ul data-role="listview" id="cptsListView" data-click="onCPTItemClicked" />
<div>PREVIOUS CPT's</div>
<ul data-role="listview" id="cptsPreviousListView" data-click="onPreviousCPTItemClicked" />
</div>
But it display like this, it's missing 2nd listview (Previous listview):
Please let me know if I did something wrong or it's a bug of Kendo UI Mobile.
Thanks
You could use
<ul data-role="listview" data-type="group" id="ListView" data-click="onItemClicked"/>
to create two group, the first for new CPT's and the second for previous CPT's.
The function onItemClicked should change its behaviour according to which group is clicked.
see the documentation for better details
Try this code
<ul data-role="listview" data-style="inset" data-type="group">
<li>NEW CPT's
<ul>
<li>
<a> 1 st item in 1st list view </a>
</li>
</ul>
</li>
<li>PREVIOUS CPT's
<ul>
<li>
<a >1 st item in 2nd list view </a>
</li>
<li>
<a >2nd item in 2nd list view </a>
</li>
</ul>
</li>
</ul>
For live demo click Here

Jquery Mobile panel dynamic listview does not render correctly

I have a searchresults.php page which shows several users that have been found. Also on the searchresults.php page is a panel
<div data-role="panel" id="mypanel" data-display="overlay" data-theme="a">
<div id="loadedprofile">
</div>
</div><!-- /panel -->
When I click on one of the "user divs" the following Jquery function fires to open the panel:
a panel on select of a search result.
The JQuery code:
$('[id=profile]').on("click", function(e) {
e.preventDefault();
var userid = $(this).attr('userid');
//window.location.href = "userdetails.php?userid=" + userid;
$("#mypanel").panel("open");
$("#loadedprofile").load("userdetailspanel.php?userid=" + userid);
$("#mypanel").trigger("updatelayout");
$('#commandlist').listview('refresh');
$('[data-role=page]').trigger('pagecreate');
$.mobile.activePage.trigger('pagecreate');
$('#commandlist').listview().listview('refresh');
});
Ok, so the panel opens up correctly and the dynamic page (userdetailspanel.php) is loaded correctly (see image). But ALSO on the userdetailspanel.php is a listview.
<ul data-role="listview" data-inset="true" id="commandlist">
<li>
<a href="#" id="mylink" name="mylink" >
<img src='bolt.png' class="ui-li-icon" />Link
</a>
</li>
</ul>
This listview is not rendered correctly. I just see blue hyperlinks.
After appending items dynamically into panel, call .trigger('pagecreate');
$('[data-role=page]').trigger('pagecreate');
or
$.mobile.activePage.trigger('pagecreate');
Demo - jQM 1.3.2 and below
For jQuery Mobile v 1.4, it is different
$('.target').trigger('create')
Demo - jQM v 1.4 Aplha
OK so the trick was to add the refresh at the bottom of the userdetailspanel part.
So, after the UL, add:
<script type="text/javascript">
$('#commandlist').listview().listview('refresh');
</script>

jQuery mobile popup dynamic URL

I have problem of dynamically URL in a popup. Here my code:
<!-- content -->
<ul data-role="listview">
<li data-role="list-divider">Group 1</li>
<li data-icon="false">List 1a</li>
<li data-icon="false">List 1b</li>
<li data-role="list-divider">Group 2</li>
<li data-icon="false">List 2a</li>
</ul><!-- /content -->
<!-- popup-menu -->
<div data-role="popup" id="popup-menu">
<ul data-role="listview" style="min-width:210px;">
<li data-role="divider">Choose an action</li>
<li>View details</li>
<li>Share</li>
</ul>
</div><!-- /popup-menu -->
Basically, when I click link on my popup, I'll go to the page where the callee's url is.
So, if I click List 1a the popup shows, then I click View details the page direct me to URL person.php?id=1
How can I do that?
I could just create popup divs multiple times according to the number of the list, but I think it's a waste of DOM object (my last resort if I don't find any elegant solution)
Thanks
Since you actually need to pass only an id of a person to your popup you can achieve your goal this way:
First of all simplify your listview markup and store an id in data-id attribute of an anchor of a listview item
<ul data-role="listview" id="list">
<li data-role="list-divider">Group 1</li>
<li data-icon="false">List 1a</li>
<li data-icon="false">List 1b</li>
<li data-role="list-divider">Group 2</li>
<li data-icon="false">List 2a</li>
</ul>
and add an id tag to 'View Details` anchor in your popup for easier access later on
<li><a id="details" href="#">View details</a></li>
Second on click() event store current id to a globally available variable (let's call it currentId) and programmatically open the popup.
var currentId = 0;
...
$('#page').on('pageinit', function(){
$('#list li a').click(function(e){
e.preventDefault();
currentId = $(this).attr("data-id");
$("#popup-menu").popup("open", {transition:"slideup"} );
});
});
Third in popupbeforeposition event construct your url and assign it to appropriate anchor.
var baseURL = "person.php?id=";
...
$('#popup-menu').on('popupbeforeposition', function(){
$("#details").attr("href", baseURL + currentId);
});
And finally here is working jsFiddle for you.

jQuery Mobile back button not showing up when linked to drop down UL

So I have one page that works perfectly fine, I am actually creating the links programatically and any link to get to the page with the working back button from is fine - I can see the back button no problem, but then I have a drop down that is just UL full of links and the two pages I link to from there don't show the back button.
Here is the top of the working page.
<div data-role="page" id="detailsPage" data-add-back-btn="true">
<div data-role="header">
<h1 id="title"></h1>
</div>
There here is the one that doesn't work.
<div data-role="page" id="calendarPage" data-add-back-btn="true">
<div data-role="header">
<h1 id="title">Calendar</h1>
</div>
Here is the UL that has the link to the calendar page that won't show a back button.
<div class="ui-block-b">
<ul data-role="menu" id="optionsDropDown">
<li>
<span data-role="button" data-icon="arrow-d" data-iconpos="right" data-iconpos="left">Calendar</span>
<ul data-role="listview" data-inset="true">
<li data-icon="false">
Thursday
</li>
<li data-icon="false">
Friday
</li>
<li data-icon="false">
List All Sessions
</li>
<li data-icon="calendar">
<a href="#calendarPage" >Calendar</a>
</li>
<li data-icon="gear">
<a href="#settingsPage" >Settings</a>
</li>
</ul>
</li>
</ul>
</div>
The back button on detailsPage always works, the back button on calendarPage never shows up. I have trolled the site but people seems to have issues when they mess with changeHash which I haven't touched.
Could I be screwing something up in the JS? I can't see anything obvious, I could post my whole JS file but I don't even touch these pages from there or mess with the links or anything. I thought maybe because the display is set to none on that list I just showed you above that it wouldn't work but then I tried changing that - it make no difference if you can see it initially or not. I don't get any errors in the console. I am so stumped at the moment. I hope someone can help.
Thanks
Not sure if it is a possible cause but according to the docs, data-role="button" is only valid on <a>, <button> and <input> type elements. I don't see <span> listed there and wonder if that is affecting your navigation?
There is also no valid data-role="menu" attribute listed.
What version of jQuery Mobile are you using? Are you relying on any third party widgets?

Jquery mobile dialog close going to far back

I currently have a dialog that allows you to download a file, and another link (the one in question) to transfer the user to another page which links you to an external API.
When I pop up the dialog, I can click on close and the dialog closes properly. When I follow the external link the page loads correctly and everything like that.
However if I hit the back button, it keeps the #ui-dialog has in the URL and nothing is loaded into the page.
I have tried to set the changehash value to false, but when I do that and if I close the dialog, it takes me too far back in my browsers history.
$(document).ready(function () {
VaultManager.GetFolderConent(VaultManager.UserRootFolderGuid, "My Vault");
$.mobile.changePage.defaults.changeHash = false;
});
function PopDialog() {
$.mobile.changePage( 'MobileFileOptions.htm', { reverse:false, transition:'pop', role:'dialog' });
}
Instead of PopDialog(), I also tried this:
<a href="MobileFileOptions.htm" data-rel="dialog" data-transition="pop">
Here is MobileFileOptions.htm:
<div data-role="page">//I have tried data-role="dialog" as well
<div data-role="header" data-theme="e">
<h1 id="popupHeader">File</h1>
</div><!-- /header -->
<div data-role="content">
<div id="divFileName"></div>
<div id="divFileSize"></div>
<div id="divFileCreated"></div>
<ul data-role="listview" data-inset="true">
<li>Download</li>
<li>
<a href="BoxManager.aspx" data-rel="external" id="boxLink">
Send to Box.NET
</a>
</li>
</ul>
</div><!-- /content -->
</div>
Am I missing something somewhere?
I am fairly new with jQuery Mobile, so, I may have done some mistakes and I can't figure out to get much help from the docs.

Resources