How do you make a flipswitch on the right corner of a fixed header in jQuery Mobile? - jquery-mobile

I have tried the following:
<div data-role="header" data-position="fixed" data-tap-toggle="false">
<h1>My Page</h1>
<label for="nfcSwitch" class="ui-hidden-accessible">NFC:</label>
<input data-role="flipswitch" name="nfcSwitch" id="nfcSwitch" data-on-text="NFC on" data-off-text="NFC off" type="checkbox" />
</div>
but it shows the flipswitch on the left, under the h1

HTML
<div data-role="header" data-position="fixed" data-tap-toggle="false">
<h1>My Page</h1>
<div class="switch">
<label for="nfcSwitch" class="ui-hidden-accessible">NFC:</label>
<input data-role="flipswitch" name="nfcSwitch" id="nfcSwitch" data-on-text="NFC on" data-off-text="NFC off" type="checkbox"/>
</div>
</div>
CSS
.switch
{
position: absolute;
top: 0px;
right: 0px;
}
JSFiddle

Related

Dialog close went to previous page

Expected Scenario: I have two div in one page one is popup and other is the main page. When I click on popup popup should open and when i click close on pop up it should show the other div
Actual Scenario: WHen I close it doesnot show the other div instead it goes to the previous page
Using Jquery Mobile 1.3.0
$.mobile.changePage("#publishlogonmanage", { role: "dialog", transition:"slideup",reload:false,reverse: false,changeHash: false });
PopUP COde
<div data-role="page" id="publishlogonmanage" data-history="false" data-overlay-theme="b" data-theme="b">
<div data-role="header" data-theme="a">
<a data-icon="delete" id="logonClose" data-mini="true" data-theme="a" data-rel="back" data-role="button" class="ui-btn-left"></a>
<a data-icon="delete" data-theme="a" data-transition="flip" data-rel="back" data-mini="true" data-role="button" class="ui-btn-left" style="width:80px;" >Close</a>
</div>
<div data-role="content" style="padding: 0; margin: 0; background: #FFFFFF;">
This is Body
</div>
</div>
Main Page:
<div data-role="page" data-theme="b" id="MobilePage" data-overlay-theme="b">
<div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme="a">
<div style="float: left; margin-left: 5px;"> Back</div>
<h1 id="title"> 10 </h1>
</div>
<div data-role="content" class="master-wrapper-page">
This is body
<div style="margin-top:7px;display:none;float: right !important; margin-left: 0px !important;overflow:ellipsis;white-space: nowrap;" data-close-btn="right" id="ManageLogon" data-mini="true" onclick="LoadDialog();" data-rel="popup"></div><img src="../../../images/logon-E.png" style="1px solid #666666;margin-top:3px;margin-right:-5px float: right;height:30px;width:30px;" id="logonexp" /></div>
</div>
</div>

vertical buttons alignment in jquery mobile

Hi i'm working on Mobile app. I want these 3 buttons to align vertically one below the other. what happens is , once i put them in a div (with class="footer") , the button width size changes automatically.
<div class="footer" data-role="footer" data-id="fixedFooter" data-position="fixed" style="display:none;" >
<div style="text-align:center; width:100%;">
<input type="button" value="Button">
</div>
<div>
<input type="button" value="submit">
</div>
<div>
<input type="button" value="cancel">
</div>
You need something like this: http://jsfiddle.net/Gajotres/a5USz/
HTML:
<div data-role="footer" data-position="fixed">
<div class="button-holder">
<input type="button" value="Button"/>
</div>
<div class="button-holder">
<input type="button" value="submit"/>
</div>
<div class="button-holder">
<input type="button" value="cancel"/>
</div>
</div>
CSS:
.button-holder {
text-align:center;
width:100%;
}
.button-holder .ui-btn {
width: 100% !important;
}
Add margin: 0 if you want to make them side by side, like this:
.button-holder .ui-btn {
width: 100% !important;
margin: 0 !important;
}

Centering the text in the input field in jQueryMobile on iPhone

So, if you take a look at the jsfiddle (I posted the code below for consistency) you will see that the input text is centered. However, if I visit the jsfiddle (and on my testing site) on my iPhone (iOS5) the text is just left-aligned. So, am wondering do you guys maybe know is this a know issue (googled - seems not) and do you know of a workaround.
css:
.centerText{
text-align: center;
}​
js:
$(document).ready(function(){
$( "#popupLogin" ).popup( "open" );
});​
html:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<section id="home" data-role="page">
<header data-role="header">
<h1>test page</h1>
</header>
<div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
<h3 class="centerText">Register free!</h3>
<div class="popup">
<form>
<input type="email" name="email" id="email" class="centerText" placeholder="email" data-theme="a"/>
<button type="submit" data-theme="b">Sign me up</button>
<p class="centerText">
text1<br/>
text2<br/>
etc...<br/>
</p>
</form>
</div>
</div>
</section>
</body>
</html>
Here some tinkering from your jsFiddle: http://jsfiddle.net/Twisty/jb8Jx/2/ Just shows you some ways to try and move the placeholder about.
HTML
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<section id="home" data-role="page">
<header data-role="header">
<h1>test page</h1>
</header>
<div data-role="content">
<label>Left Align</label><input type="text" placeholder="email" class="leftText">
<label>Right Align</label><input type="text" placeholder="email" class="rightText">
<label>Center Text</label><input type="text" placeholder="email" class="centerText">
<label>Pad Left</label><input type="text" placeholder="email" class="leftPadText">
</div>
<div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
<h3 class="centerText">Register free!</h3>
<div class="popup">
<form>
<input type="email" name="email" id="email" class="centerText" placeholder="email" data-theme="a" style="text-align: center;"/>
<button type="submit" data-theme="b">Sign me up</button>
<p class="centerText">
text1<br/>
text2<br/>
etc...<br/>
</p>
</form>
</div>
</div>
</section>
</body>
</html>
CSS
input.centerText{
text-align: center;
}
input.leftText {
text-align: left;
}
input.rightText {
text-align: right;
}
input.leftPadText {
padding-left: 220px;
}

How to show multi <input> in a row with jquerymobile

I want to show two date in a row with jquerymobile. But it only works in Desktop browser. In mobile browser will in independed row.
<div data-role="fieldcontain">
<label for="time_start" class="ui-hidden-accessible">time_start:</label>
<label for="time_end" class="ui-hidden-accessible">time_end:</label>
<input type="date" name="time_start" value="2011-05-30" /> — <input type="date" name="time_end" value="2011-05-30"/>
</div>
Have you tried putting the labels and the input inside a span?
Float:left and width:80 (for example) should do the trick for you. Here is an example in both small buttons and large ones.
http://jsfiddle.net/den232/SN85d/
Good luck!
.floatleft {
float:left;
}
.floatright {
float:right;
}
.forceinline{ /* Prevent fieldcontain from doing a BLOCK thing */
display:inline !important;
}
.textwidth { /* limit width of input fields */
width:80px;
}
.closespacing { /* controls spacing between elements */
margin:0px 5px 0px 0px;
}
.bigselect { /* centers select with big buttons */
padding: 0px;
margin:2px 5px 0px 0px;
}
.biginputheight { /* matches text input height to big buttons */
padding-top:10px !important;
padding-bottom:12px !important;
}
.miniinputheight { /* matches text input height to minibuttons */
padding-top:5px !important;
padding-bottom:5px !important;
}
<div data-role="page" class="type-home">
<ul data-role="listview">
<li data-role="fieldcontain">first LI line</li>
<li data-role="fieldcontain">
<div class='floatleft closespacing'>
Big Buttons<br>More Text
</div>
<div class='floatleft textwidth'>
<input type="date" placeholder="#1" class='biginputheight'></input>
</div>
<div class='floatleft textwidth'>
<input type="date" placeholder="#2" class='biginputheight'></input>
</div>
</li>
<li data-role="fieldcontain">
<div class='floatleft closespacing'>
Small Buttons
</div>
<div class='floatleft textwidth'>
<input type="date" placeholder="s1" class='miniinputheight'></input>
</div>
<div class='floatleft textwidth'>
<input type="date" placeholder="s2" class='miniinputheight'></input>
</div>
</li>
<li data-role="fieldcontain">last LI line</li>
</ul><!-- /listview -->
maybe you can achive it using grids
<div class="ui-grid-a">
<div class="ui-block-a"><label for="time_end" class="ui-hidden-accessible">
time_end: </label>
<div class="ui-block-b"><label for="time_end" class="ui-hidden-accessible">
time_end: </label>
</div>

Why does this jQuery Mobile multipage trigger multiple submit events?

Below is a test page. If I go through all the JQM 'pages' and then go back to the first page, and then click submit, the 'SUBMITTING' alert dialog will pop up 4 times. What am I doing wrong? What should I do to make the submit event fire only once?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<script type="text/javascript" charset="utf-8" src="js/phonegap.js"></script>
<link rel="stylesheet" href="jquery-mobile/jquery.mobile.css"/>
<link rel="stylesheet" href="css/custom-icons.css"/>
<link href="css/jquery.mobile-swatch-f.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery.js"></script>
<script src="jquery-mobile/jquery.mobile.js"></script>
<script>
$('div:jqmData(role="page")').live('pageinit', function() {
$('form').submit(function(e) {
alert("SUBMITTING");
});
});
</script>
</head>
<body>
<form id="frm_testform_happy_party">
<div data-role="page" id="testform_menu" data-theme="f" class="dummyclass">
<div data-role="header">
<h1>Testing testing</h1>
</div>
<div data-role="content">
<ul data-role="controlgroup">
<li><a target_id="testform_happy" href="#testform_happy" data-role="button"
style="text-align:left" data-icon="arrow-r"
data-iconpos="right" class=".ui-icon-manditory">happy party</a></li>
<li><a target_id="testform_description" href="#testform_description" data-role="button"
style="text-align:left" data-icon="arrow-r"
data-iconpos="right">Description</a></li>
<li><a target_id="testform_vehicle" href="#testform_vehicle" data-role="button"
style="text-align:left" data-icon="arrow-r" data-iconpos="right">Vehicle</a>
</li>
</ul>
<input id="submit_claim" type="submit" name="send" value="Submit" id="submit"/>
<div id="debug">
</div>
</div>
<div data-role="footer" data-position="fixed" class="ui-btn-right" style="min-height:42px;">
<a href="index.html#claim_menu" rel="external" data-icon="arrow-l" data-direction="reverse"
data-iconpos="left"
style="margin-left: 10px; margin-top: 5px">Done</a>
<a href="index.html" data-icon="home" data-direction="reverse" data-iconpos="notext"
style="float: right; margin-right: 10px; margin-top: 5px"></a>
</div>
</div>
<div data-role="page" id="testform_happy" data-theme="f">
<div data-role="header">
<h1>Happy Party</h1>
</div>
<div data-role="content">
<label for="happy_initials">Initials:</label>
<input type="text" name="happy_initials" id="happy_initials" value="" class="required"/>
</div>
<div data-role="footer" data-position="fixed" class="ui-btn-right" style="min-height:42px;">
<a href="#testform_menu" data-icon="arrow-l" data-direction="reverse" data-iconpos="left"
style="margin-left: 10px; margin-top: 5px">Done</a>
<a href="index.html" data-icon="home" data-direction="reverse" data-iconpos="notext"
style="float: right; margin-right: 10px; margin-top: 5px"></a>
</div>
</div>
<div data-role="page" id="testform_description" data-theme="f">
<div data-role="header">
<h1>Description</h1>
</div>
<div data-role="content">
<label for="incident_date">Date of Incident:</label>
<input type="date" name="incident_date" id="incident_date" value="" class="required"/>
</div>
<div data-role="footer" data-position="fixed" class="ui-btn-right" style="min-height:42px;">
<a href="#testform_menu" data-icon="arrow-l" data-direction="reverse" data-iconpos="left"
style="margin-left: 10px; margin-top: 5px">Done</a>
<a href="index.html" data-icon="home" data-direction="reverse" data-iconpos="notext"
style="float: right; margin-right: 10px; margin-top: 5px"></a>
</div>
</div>
<div data-role="page" id="testform_vehicle" data-theme="f">
<div data-role="header">
<h1>Vehicle</h1>
</div>
<div data-role="content">
<label for="vehicle_registration_number">Registration Number:</label>
<input type="text" name="vehicle_registration_number" id="vehicle_registration_number" value=""
class="required"/>
</div>
<div data-role="footer" data-position="fixed" class="ui-btn-right" style="min-height:42px;">
<a href="#testform_menu" data-icon="arrow-l" data-direction="reverse" data-iconpos="left"
style="margin-left: 10px; margin-top: 5px">Done</a>
<a href="index.html" data-icon="home" data-direction="reverse" data-iconpos="notext"
style="float: right; margin-right: 10px; margin-top: 5px"></a>
</div>
</div>
</form>
</body>
</html>
You're doing this:
<script>
$('div:jqmData(role="page")').live('pageinit', function() {
$('form').submit(function(e) {
alert("SUBMITTING");
});
});
</script>
I think this is firing for every page loaded, correct?
Maybe try something like this:
<script>
$(function() {
$('#submit_claim').click(function() {
$('form').submit(function(e) {
alert("SUBMITTING");
});
});
});
</script>

Resources