register virtual taphold event for jQuery mobile Flip toggle switch - jquery-mobile

I can't figure out how to register the taphold event for a Flip toggle switch. I tried as described here with the following code.
<div data-role="fieldcontain">
Sex
<select name="sex" id="id" data-role="slider">
<option value="off">Male</option>
<option value="on">Female</option>
</select>
</div>
$('#id').live('taphold', function(){
console.log("taphold");
});
And, because the actual <select> tag is hidden, and the switch is rendered by following html
<div role="application" class="ui-slider ui-slider-switch ui-btn-down-c ui-btn-corner-all ui-focus">
<span class="ui-slider-label ui-slider-label-a ui-btn-active ui-btn-corner-all" role="img" style="width: 100%">Female</span>
<span class="ui-slider-label ui-slider-label-b ui-btn-down-c ui-btn-corner-all" role="img" style="width: 0%">Male</span>
<div class="ui-slider-inneroffset">
<a href="#" class="ui-slider-handle ui-btn ui-shadow ui-btn-corner-all ui-slider-handle-snapping ui-focus ui-btn-up-c" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c" role="slider" aria-valuemin="0" aria-valuemax="1" aria-valuenow="on" aria-valuetext="Female" title="Female" aria-labelledby="eforms_patient_sex-label" style="left: 100%">
<span class="ui-btn-inner ui-btn-corner-all">
<span class="ui-btn-text"/>
</span>
</a>
</div>
</div>
Which is a sibling of aboves <select> tag I also tried this
$('#id').parent().find('[role="application"]').live('taphold', function(){
console.log("taphold");
});
But nether did work. So...
How to register the virtual taphold event for jQuery mobile Flip toggle switch?
//edit
I added a onclick function to the <div> tag, via opera dragonfly, and it worked. So It seams that registering the event to the <div> is the right approach. But it does not work, with the code above.

The event is called taphold not tabhold.

Related

How to add flip switch at right side of header using jquery mobile?

I wanna add flip switch at right side of header using jquery mobile. I tried this but it goes to next line.
<div data-role="header" >
<a href="#main-panel" class="ui-btn ui-btn-c ui-btn-corner-all ui-alt-icon ui-nodisc-icon ui-btn-icon-notext ui-icon-bars" ></a>
<h1>Flowers</h1>
<fieldset>
<div data-role="fieldcontain" class="">
<input type="checkbox" id="checkbox-based-flipswitch" data-role="flipswitch" data-on-text="True" data-off-text="False">
</div>
</fieldset>
</div>
All you need to do is to place your flipswitch inside of a "control-group" element.
<fieldset data-role="controlgroup" data-type="horizontal" class="ui-btn-right">
<input type="checkbox" id="checkbox-based-flipswitch" data-role="flipswitch" data-on-text="True" data-off-text="False">
</fieldset>

Custom listview with checkbox, image and button in jQuery Mobile

I am working in Listview in jQuery Mobile dynamically. I can't make this design.
Code:
<li data-role="list-divider" role="heading">Category</li>
<li id="305"> <a href="#" class="achk">
<fieldset data-role="controlgroup" style="width:53px;">
<input type="checkbox" name="checkbox_attribute_0" id="checkbox_attribute_0" data-iconpos="notext" /> <label for="checkbox_attribute_0" action="selectAttribute" data="test"></label>
</fieldset>
<label onclick="viewMessage(305, 0);" class="lblImage" data-corners="false">
<fieldset data-role="controlgroup" style="height:0px !important">
<img alt="" src="img/letter.png" />
</fieldset>
</label>
<div onclick="viewMessage(305, 0);" >
<h4>Advanced-customization-Jquery-Mobile-Buttons </h4>
<p>Advanced-customization-Jquery-Mobile-Buttons</p><p>Date : November 15, 2013</p>
</div>
Delete
</a>
</li>
Here is the jsfiddle of the code I have done so far.
Add these lines in your function.
$("#inbox_list").trigger("create");
$("#inbox_list").listview("refresh");
Update Code
$('#dvCount').html(data.count);
//$('input[type=checkbox]').checkboxradio().trigger('create');
$('[data-role="listview"]').html( list ).trigger('create');
$('[data-role="listview"]').listview('refresh');

Why copy paste option come when we tap the the button for 5 seconds?

Can you please tell me why copy, paste option appears after tapping the button for 5 seconds in jQuery mobile? Actually I am using jQuery mobile When I Add button and tap on that it show copy paste select all options?
<div class="ui-grid-c">
<div class="ui-block-a" style="width: 30%;" >
<input name="text-12" id="text-12" value="" type="text" autocorrect="off" class="searchbox">
</div>
<div class="ui-block-b">
Search
</div>
<div class="ui-block-c" style="margin-left: 5px;">
<a href="#" data-role="button" data-corners="false" data-inline="true" id="next" class="searchNext" disabled>Next</a>
</div>
<div class="ui-block-d" style="margin-left: 30px;">
<a href="#" data-role="button" data-corners="false" data-inline="true" id="prev" class="searchPrev" disabled>Previous</a>
</div>
Please Take a look On this link
Apache Cordova: remove tap-hold link menu
Disable copy on jquery mobile button over PhoneGap
Use This
* {
-webkit-touch-callout: none;
-webkit-user-select: none;
}
and only enable something you like:
input {
-webkit-user-select: auto;
}

Archieve a Header and "Sub-Header" with jQuery Mobile

I am failing to correctly organize jQuery Mobile components in the following way:
I was trying to build this fixed searchbar, but after many attemps I ended up here, asking for help.
<div data-role="header" data-position="fixed" data-theme="b">
<a data-role="button" class="ui-btn-lft" href="#pgIndex" data-icon="arrow-l" data-theme="b">Back</a>
<h1>Title</h1>
</div>
<div data-role="header" data-theme="b" id="second-header">
<div style="float:left; width: 75%;">
<select name="selCombo1" id="selCombo1" data-mini="true">
<option value="0">Option 0 - All</option>
</select>
<span style="margin-bottom: 3px;"></span>
<select name="selCombo2" id="selCombo2" data-mini="true">
<option value="0">Option 0 - All</option>
</select>
</div>
<div style="float:right; width: 25%;">
<a data-role="button" data-mini="true" data-icon="search" data-iconpos="top" data-rel="back">Search</a>
</div>
</div>
Is there a simple way to archieve this?
The complete code is on jsFiddle:
http://jsfiddle.net/mbarni/rjdt2/
You can achieve a similar effect to a second header level by appending a div with the classes:
class="ui-bar ui-bar-b"
to your header. Here's a simple example using your code.
JSFiddle Example
For more info, check the bottom of this doc

Jquery Mobile popup triggering by itself

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.

Resources