Delete list element from a confirmation popup - jquery-mobile

I have a list with delete button for each element , when the user click on the delete button a confirmation dialog appear ,if the user press the OK button i want to delete the list element my problem is how to get the <li> list element index in order to remove it from the list , my code not return the correct index , please help me ..
<div data-role="page">
<div data-role="content">
<ul data-role="listview" id="employeesList" data-inset="true" data-split- icon="delete">
<li><a href="#">
<font class="line1" > Emp1Name</font>
<font class="line2" >Emp1Salary</font>
</a><a href="#DeleteConfirm" data-rel="popup" data-position-to="window" data- transition="pop" >Delete</a></li>
<li><a href="#">
<font class="line1" > Emp2Name</font>
<font class="line2" >Emp2Salary</font>
</a>Delete</li>
</ul>
<div data-role="popup" id="DeleteConfirm" data-overlay-theme="a" data-theme="c" data-dismissible="false" style="width:400px;height:200px;" class="ui-corner-all">
<div data-theme="c" style="text-align:center;float:center;height:53px;padding-top:13px;" >
<font size="6px" >Delete</font>
</div>
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
<font size="5px" >Do you want to delete this Employee?</font>
<BR>
<div style="text-align:center;font-size: 22px;" >
<input type="button" id="No" data-inline="true" data-icon="delete" data-theme="c" value="No " />
<input type="button" id="Yes"data-inline="true" data-icon="check" data- theme="c" value=" Yes" data-corners="false"/>
</div>
</div>
</div>
</div>
Java script code:
var SelectedLi ;
$('#DeleteConfirm').on('click',function(){
SelectedLi= $(this).parent().index();
});
$('#Yes').on('click',function(){
$('#employeesList').remove(SelectedLi);
$('#DeleteConfirm').popup('close');
});
$('#No').on('click' ,function(){
$('#DeleteConfirm').popup('close');
});

You have mistake in binding event to split button, it should be as follows:
var SelectedLi ='' ;
$('[href=#DeleteConfirm]').on('click',function (e) {
// store parent of clicked button
SelectedLi = $(this).closest("li");
});
$('#Yes').on('click',function(){
$(SelectedLi).remove();
$('#employeesList').listview("refresh");
$('#DeleteConfirm').popup('close');
});
$('#No').on('click' ,function(){
$('#DeleteConfirm').popup('close');
});
Demo

This is how I do my popup:
HTML:
<div data-role="popup" id="sterge" data-overlay-theme="a" data-theme="c" data-dismissible="false" style="max-width:400px;" class="ui-corner-all">
<div data-role="header" data-theme="b" class="ui-corner-top">
<h1>Delete?</h1>
</div>
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
<h3 class="ui-title">To Delete Product from Bonus?</h3>
<p>This action cannot be undone.</p>
<input id="giveupButton" data-inline="true" type="button" value="Cancel"/>
<input id="delButton" data-inline="true" onclick="deletebonusproduct();" data-theme="b" type="button" value="Delete"/>
</div>
</div>
JS:
$(document.body).on('click', '.del' ,function(){
li = $(this).parent();
$('#sterge').popup("open");
});
$(document.body).on('click', '#delButton' ,function(){
$('#sterge').popup("close");
li.remove();
});
$(document.body).on('click', '#giveupButton' ,function(){
$('#sterge').popup("close");
});

Related

Get text of parent dt in Description List

I have a JQuery Mobile popup (an unordered list) embedded in a description list:
<dl data-role="listview" data-inset="true" data-theme="d" id="sortable">
<dt class="ui-bar ui-bar-b ui-corner-all">Group One</dt>
<dd class="ui-bar ui-bar-a ui-corner-all ui-btn-icon-left ui-icon-bars">
<div class="divMain">
<div class="divQuestion">
<textarea name="strQuestion-q1" id="strQuestion-q1" placeholder="Enter Question Number 1" style="margin:0px;"></textarea>
</div>
<div class="divCategory">
<a class="ui-btn ui-corner-all ui-shadow ui-btn-inline" href="#popupMenu-q1" data-rel="popup" data-transition="slideup">Select Category</a>
<div id="popupMenu-q1" data-role="popup" data-theme="b">
<ul style="min-width: 210px;" data-role="listview" data-inset="true">
<li data-role="list-divider">Choose the scoring category</li>
<li><a name="strCategory-o1-q1" href="javascript:void(0);" onclick="selectCategory(this);">Category 1</a></li>
<li><a name="strCategory-o2-q1" href="javascript:void(0);" onclick="selectCategory(this);">Category 2</a></li>
<li><a name="strCategory-o3-q1" href="javascript:void(0);" onclick="selectCategory(this);">Category 3</a></li>
</ul>
</div>
</div>
</div>
</dd>
</dl>
I want the function selectCategory() to get the text of the parent dt (in this case "Group One"). I've tried both of the following with no success:
$('#strCategory-o1-q1').parent().prev('dt').text();
$('#strCategory-o1-q1').closest('dd').prev('dt').text();
Any suggestions?
The problem is that when jQM initializes the popup, it moves it from the current DOM position into a popup container at the top level. So the DD is no longer its ancestor.
One thing you could do is add a click handler to the button that launches the popup and get the text there. Then you could put the text in a global variable or a data-attribute within the popup.
Given this markup:
<a id="btnPopup" class="ui-btn ui-corner-all ui-shadow ui-btn-inline" href="#popupMenu-q1" data-rel="popup" data-transition="slideup">Select Category</a>
<div id="popupMenu-q1" data-role="popup" data-theme="b">
<ul style="min-width: 210px;" data-role="listview" data-inset="true">
<li data-role="list-divider">Choose the scoring category</li>
<li><a name="strCategory-o1-q1" href="#">Category 1</a></li>
<li><a name="strCategory-o2-q1" href="#">Category 2</a></li>
<li><a name="strCategory-o3-q1" href="#">Category 3</a></li>
</ul>
</div>
Your script would be along the lines of
var curDDText;
$("#btnPopup").on("click", function(){
curDDText = $(this).closest('dd').prev('dt').text();
});
$("#popupMenu-q1 ul li a").on("click", function(e){
selectCategory(this);
});
function selectCategory(elem){
alert($(elem).prop("name") + " - " + curDDText);
$("#popupMenu-q1").popup( "close" );
}
working DEMO
If you prefer the data-attribute route:
$("#btnPopup").on("click", function(){
var curDDText = $(this).closest('dd').prev('dt').text();
$("#popupMenu-q1 ul").jqmData("dttext", curDDText);
});
function selectCategory(elem){
var curDDText = $(elem).closest("ul").jqmData("dttext");
alert($(elem).prop("name") + " - " + curDDText);
$("#popupMenu-q1").popup( "close" );
}
data-attribute DEMO

Page redirection issues with a popup/button (jQuery mobile)

I've created a button
<a data-role="button">
inside a Popup. Here is Popup:
<div data-role="popup" id="popupRegister" data-theme="a" data-dismissible="false">
<div data-role="header" data-theme="b" class="ui-header ui-bar-b"
role="banner">
<h1 class="ui-title" role="heading" aria-level="1">Success!!</h1>
</div>
<div data-role="" data-theme="a" class="ui-body-a"
role="main" style="padding:15px;">
<h1>Thank you for regestering with us.</h1>
<p>You may now continue to the app.</p>
<!-- this is the button -->
<a href="#" id="takeMeHome" data-role="button" data-rel="back"
data-theme="a" data-inline="true"
data-corners="true" data-shadow="true"
data-iconshadow="true" data-wrapperels="span"
class="ui-btn ui-shadow ui-btn-corner-all ui-btn-inline ui-btn-up-a">
<span class="ui-btn-inner"><span class="ui-btn-text">GO</span></span>
</a>
</div>
</div>
When I click the button, console.log is responding but page does not redirect. Why?
Here is how I redirect:
$("#takeMeHome").click( function(){
console.log("lets go home");
//window.location.href = "home.html";
//localStorage.registered=true;
//window.location.replace("home.html");
window.location.href = ("home.html");
});
Replace
window.location.href = ("home.html");
with
$.mobile.changePage('home.html');
And add data-history="false" to popup div.

Panels and fixed-position header/footer

I am trying to use the reveal animation for my panel. However, when jQuery Mobile runs the animation, the header does not slide over as far as the panel does so the header slightly overlaps the panel. See the image here: http://i.imgur.com/fjuDSRe.png
Here's my code:
<div data-role="page" id="taskdetailspage">
<div data-role="header" data-id="navbar" data-position="fixed" data-tap-toggle="false">
Back
<p class="title">Field Service Engineer</p>
Actions
</div>
<div id="taskholder" data-role="content">
</div>
<div data-role="content" id="directionsholder"></div>
<div data-role="panel" data-theme="a" id="taskdetailspanel" data-position="right" data-display="reveal"
data-position-fixed="true">
<h3>Actions</h3>
<ul data-role="listview" data-theme="a">
<li>Update Task Status</li>
<li><a id="directionsButton" href="#">Get Directions</a></li>
<li>Decline Task</li>
</ul>
</div>
<div id="updateStatusPopup" data-role="popup" data-theme="a" data-overlay-theme="a"
data-transition="fade" data-position-to="window">
<div data-role="header">
<h3>Update Task Status</h3>
</div>
<div data-role="content">
<form action="javascript: updateTaskStatus(currentTaskId);">
<fieldset data-role="controlgroup">
<legend>Current Status:</legend>
<input data-theme='a' name="updateStatus" id="arrived" value="Arrived" checked="checked" type="radio">
<label for="arrived">Arrived</label>
<input data-theme='a' name="updateStatus" id="wip" value="Work in Progress" type="radio">
<label for="wip">Work in Progress</label>
<input data-theme='a' name="updateStatus" id="completed" value="Complete" type="radio">
<label for="completed">Complete</label>
</fieldset>
<label for="statusNotes">Status Notes:</label>
<input name="statusNotes" id="statusNotes" value="" type="text">
<fieldset class="ui-grid-a">
<div class="ui-block-a"><input type="submit" value="Update" data-theme='a' id='confirmUpdateButton'></div>
<div class="ui-block-b"><a data-theme='a' data-role='button' data-rel='back'>Cancel</a></div>
</fieldset>
</form>
</div>
</div>
<div id="dialogcontent" data-role="popup" data-theme="a" data-overlay-theme="a"
data-transition="fade" data-position-to="window">
<div data-role="header">
<h3>Confirm Decline Task</h3>
</div>
<p>Are you sure you want to decline this task and remove it from your calendar?</p>
<fieldset class="ui-grid-a">
<div class="ui-block-a"><a data-theme='a' href='#' id='confirmDeclineButton' data-role='button'>Decline</a> </div>
<div class="ui-block-b"><a data-theme='a' href='#' data-role='button' data-rel='back'>Cancel</a></div>
</fieldset>
</div>
I found one other question on SO with a similar description but the solution was unintelligible.
Thanks in advance!

why thems go up when entering the text in text field? [duplicate]

This question already has an answer here:
How to handle them jump out(while keyboard open) in query mobile?
(1 answer)
Closed 9 years ago.
I am using jqm .Actually I open the pop up screen on button click .I am facing a problem my them goes up while entering the text.Here is my code..
http://jsfiddle.net/ravi1989/7JqRG/
<div data-role="page" id="Home" >
<div data-role="header" data-theme="b" data-position="fixed" data-tap-toggle="false" >
<h1 class="ui-title" id="hdr" style="text-align:left;margin-left: 20px;">My Cases</h1>
<div class="ui-btn-right" id="headerButtons" data-role="controlgroup" data-type="horizontal">
Setting
Add
Edit
</div>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true" id="folderData" >
</ul>
<!-- **************Case Information Pop up Start*******************-->
<div data-role="popup" id="CaseInformationScreen" data-close-btn="none" data-overlay-theme="a" data-dismissible="false">
<div data-role="header" data-theme="b" >
Cancel
<h1>Case Information</h1>
Add
</div>
<div data-role="content">
<div><img src="img/Documents.png"/></div>
<div data-role="fieldcontain">
<label for="text-12" style="text-align:top;margin-left: 0px;">Case Name:</label>
<input name="text-12" id="text-12" value="" type="text" class="caseName_h" autocorrect="off">
</div>
<div data-role="fieldcontain">
<label for="caseDate" style="text-align:left;margin-left: 0px;" >Case Date:</label>
<input name="caseDate" id="caseDate" value="" type="date" class="caseDate_h" >
<!--input name="mydate2" id="mydate2" type="date" data-role="datebox" class="caseDate_h" data-options='{"mode": "calbox","useNewStyle":true,"zindex":1200}'/-->
</div>
<div data-role="fieldcontain">
<label for="textarea-12">Case Notes :</label>
<textarea cols="40" rows="8" name="textarea-12" id="text-12" class="caseTextArea_h" autocorrect="off"></textarea>
</div>
</div>
</div>
Please + button on header .Pop up open fill the text black them goes up?
Here is your answer..
window.resize due to virtual keyboard causes issues with jquery mobile
1) Go into jquery.mobile-1.x.x.js
2) Find $.mobile = $.extend() and add the following attributes:
last_width: null,
last_height: null,
3) Modify getScreenHeight to work as follows:
getScreenHeight: function() {
// Native innerHeight returns more accurate value for this across platforms,
// jQuery version is here as a normalized fallback for platforms like Symbian
if (this.last_width == null || this.last_height == null || this.last_width != $( window ).width())
{
this.last_height = window.innerHeight || $( window ).height();
this.last_width = $(window).width();
}
return this.last_height;
}

jQueryMobile : How to add contents to Collapsible Div Dynamically

I have a collapsible-set div and within that 2 collapsible divs.
And I have to dynamically add elements to these collapsible divs dynamically, when clicking a plus button. I have tried many codes, but didn't work. Could you please tell me how to do that?
HTML Code
<div data-role="content">
<div data-role="collapsible-set" id="setAllCategory">
<div data-role="collapsible" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u" id="setCategory1">
<h1 ><label>Food</label>
<a data-role="button" id="btnAddSubCat1" name="btnAddSubCat1" data-rel="popup" href="#" data-icon="plus" data-iconpos="notext" style="float:right;" ><a/></h1>
</div>
<div data-role="collapsible" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u" id="setCategory2">
<h1 ><label>Dress</label>
<a data-role="button" id="btnAddSubCat2" name="btnAddSubCat2" data-rel="popup" href="#" data-icon="plus" data-iconpos="notext" style="float:right;" ><a/></h1>
</div>
</div>
</div>
JavaScript
var subCatObject = "<div class='ui-grid-b'>"
subCatObject +="<div class='ui-block-a'><label>Hi</label></div>"
subCatObject +="<div class='ui-block-b'><a href='#' data-role='button' data-iconpos='notext' data-icon='edit'></a></div>"
subCatObject +="<div class='ui-block-c'><a href='#' data-role='button' data-iconpos='notext' data-icon='delete'></a></div>"
subCatObject +="</div>";
$('#btnAddSubCat1').click(function (){
var temp = $(subCatObject);
$(temp).appendTo('#setCategory1').page();
$("#setCategory1").collapsibleset('refresh');
});
I changed your HTML as below
<div data-role="page" id="home">
<div data-role="content">
<div data-role="collapsible-set" id="setAllCategory" data-content-theme="d">
<div data-role="collapsible" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u"
id="setCategory1">
<h1><label>Food</label>
<a data-role="button" id="btnAddSubCat1" name="btnAddSubCat1" data-rel="popup" href="#" data-icon="plus" data-iconpos="notext" style="float:right;" ><a/></h1>
<div id="setCategoryContent1"></div>
</div>
<div data-role="collapsible" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u"
id="setCategory2">
<h1><label>Dress</label>
<a data-role="button" id="btnAddSubCat2" name="btnAddSubCat2" data-rel="popup" href="#" data-icon="plus" data-iconpos="notext" style="float:right;" ><a/></h1>
</div>
</div>
</div>
</div>
and your javascript as below
var subCatObject = "<div class='ui-grid-b'>"
subCatObject += "<div class='ui-block-a'><label>Hi</label></div>"
subCatObject += "<div class='ui-block-b'><a href='#' data-role='button' data-iconpos='notext' data-icon='edit'></a></div>"
subCatObject += "<div class='ui-block-c'><a href='#' data-role='button' data-iconpos='notext' data-icon='delete'></a></div>"
subCatObject += "</div>";
$('#btnAddSubCat1').bind('click', function () {
$("#setCategoryContent1").html(subCatObject);
$('#home').trigger('create');
});
I hope you will be able to take up from here.
Check out the working fiddle here http://jsfiddle.net/PKeSB/2/

Resources