Get checked radio button when migrate to JQM 1.1 RC1 not working - jquery-mobile

To get the value of checked radio button I use something like this
$('input:radio[name=rbutton]:checked').val()
This work well until I upgrade the version of jQuery Mobile from 1.0 to 1.1 rc1, then i could not get the value anymore, i just get "undefined"
I dont understand why something basic like this does not work for a change of JQM lib..
I paste and example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test radio button</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.js"></script>
<script>
$(document).delegate("#test", "pageinit", function(event) {
$("button.select").bind ( "click", function (e) {
// Get value of checked radio with JQM 1.0, but get "undefined" with JQM 1.1 RC
alert( $('input:radio[name=rbutton]:checked').val() );
});
$("input[type=radio]").bind ( "change", function (e) {
alert ($(this).val()); //OK
});
});
</script>
</head>
<body>
<div data-role="page" id="test" >
<div data-role="content">
<fieldset data-role="controlgroup">
<input type="radio" name="rbutton" id="rbutton1" value="1" />
<label for="rbutton1">Option 1</label>
<input type="radio" name="rbutton" id="rbutton2" value="2" />
<label for="rbutton2">Option 2</label>
</fieldset>
<button class="select">selected</button>
</div> <!-- /content -->
</div><!-- /page -->
</body>
</html>

This was a bug and is now fixed:
https://github.com/jquery/jquery-mobile/issues/3687#issuecomment-4251371

Related

jQuery datepicker doesn't appear in Firefox

I have an input form using FLAT UI KIT that MUST contain a datepicker, so I chose to use jQuery's widget. But when I run it in Chrome the datepicker shows up, whilet on Firefox it is shows as a simple text input.
Here is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My test ยท stuff with datepicker</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Loading Bootstrap -->
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="bootstrap/css/prettify.css" rel="stylesheet">
<!-- Loading Flat UI -->
<link href="css/flat-ui.css" rel="stylesheet">
<link href="css/docs.css" rel="stylesheet">
<link rel="shortcut icon" href="images/favicon.ico">
<!-- my addition jQuery UI for datepicker -->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="js/jquery.ui.touch-punch.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-select.js"></script>
<script src="js/bootstrap-switch.js"></script>
<script src="js/flatui-checkbox.js"></script>
<script src="js/flatui-radio.js"></script>
<script src="js/jquery.tagsinput.js"></script>
<script src="js/jquery.placeholder.js"></script>
<script src="bootstrap/js/google-code-prettify/prettify.js"></script>
<script src="js/application.js"></script>
<style>
.containerx {
background-color: #1abc9c;
background-repeat: no-repeat;
background-position: bottom right;
background-attachment: scroll;
}
.titluedit{
margin: 0 0 0 0;
font-size:14px;
}
.titlueditx{
margin: 0 0 0 0;
font-size:14px;
color:red;
}
fieldset { margin: 0 0 10px 0; }
</style>
<script>
</script>
<script>
$(document).ready(function(){
$(function() {
$( "#datepicker" ).datepicker();
});
});
</script>
</head>
<body>
<img src="images/logo2.png" alt="logox" height="81" width="305">
<h1 class="demo-panel-title" style="text-align:center; color:#d35400">XXXXXXXXX</h1>
<h3 class="demo-panel-title" style="text-align:center; color:#1abc9c">New info</h3>
<div class="container" style="width:900px; margin:0 auto;">
<form action="save.php" method="post">
<div class="container" style="width:700px; margin:0 auto;">
<fieldset>
<p class="titlueditx">Name *:</p>
<input type="text" name="nume" value="" placeholder="Name" class="form-control" />
</fieldset>
<fieldset>
<p class="titlueditx">Medium time *:</p>
<input type="text" name="durata" value="" placeholder="minutes" class="form-control" />
</fieldset>
<p class="titlueditx">Start date *:</p>
<input type="date" id="ui-datepicker" name="dataang" value="" class="form-control"/><br>
<fieldset>
<p class="titlueditx">Some other stuff *:</p>
<input type="text" name="sefutzul" value="" placeholder="Other relevant stuff" class="form-control" />
</fieldset>
</div>
<br><br>
<div class="container" style="width:700px; margin:0 auto;">
<table>
<tr>
<td>
<input type="hidden" id="idhidfirma" name="idfirma" value="1" />
<input type="hidden" id="idhnumefirma" name="numefirma" value="xxxxx" />
<button type="submit" class="btn btn-hg btn-primary"> Save info </button>
</form>
</td>
<td>
<form action="mylist.php" method="post">
<INPUT TYPE="hidden" NAME="idfirma" value="1">
<INPUT TYPE="hidden" NAME="numefirma" value="xxxxx">
<button type="submit" class="btn btn-hg btn-danger"> Cancel </button>
</form>
</td>
</tr>
</table>
</div>
</div>
</body></html>
What can I do to make it work in Firefox TOO?
Also in Chrome how can I make the calendar to close onClick on a day? Right now the calendar stays shown until i click somewhere else on the screen.
The problem is not Firefox, you are defining:
an input type=date with id ui-datepicker
binding a jQuery UI datepicker to an id datepicker
The 2nd selector not match any element so the jQuery UI datepicker is not binded to anything; by using an input type=date Chrome renders automatically a calendar control, so you see a calendar in Chrome because of the input type (see. https://plus.google.com/+GoogleChromeDevelopers/posts/hTcMLVNKnec)
To fix the issue in all browser you can set input type=text in your ui-datepicker element, and set the correct selector.
Code:
$(document).ready(function () {
$("#ui-datepicker").datepicker();
});
Demo: http://jsfiddle.net/IrvinDominin/zAKQe/
Date picker is working with firefox, but z-index of datepicker is in "-". So it's not appearing in firefix browser.
Show update the z-index of datepicker through jquery it will appear.
$(".datepicker").css("z-index","100");
it will work on mozila firefox if is not working update your firefox version .
i run this it works. thanks
<head>
<meta charset="UTF-8" />
<title>Datepicker fadein</title>
<link href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<script type="text/javascript">
$(function(){
$('.datepicker').datepicker({showAnim: "fadeIn"});
})
</script>
in your body of the page use the input
<input class="datepicker">

jQuery Mobile click button but nothing happens

I've poked around and found similar questions, but none of the solutions have worked.
I'm writing a simple (so far) app that will allow the user to select a number from 1-6 on a form, then display the that value (1-6) on another page. It works fine on my desktop, but when I try it from the iPhone emulator I click "Submit" and nothing happens at all... as if I didn't even click it.
I'm using jQuery 1.10.1 and jQuery Mobile 1.3.1. I'll add that this is a PhoneGap app using Adobe's PhoneGap Build service.
Here's the code for my main page:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Value Submit</title>
<link rel="stylesheet" type="text/css" href="css/jquery-mobile.css" />
<link rel="stylesheet" type="text/css" href="css/themes/aw-theme2.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-mobile-min.js"></script>
<script type='text/javascript'>
$(document).on('pageinit', function() {
$(document).on('click', '#submitroll', function() {
var dieRoll = $("#dieresult").val();
$.mobile.changePage('valuedresult.html', { data: {arg1:dieRoll}});
return false;
});
});
$(document).on('pageinit', '#valued', function() {
var dieRoll = $("#dieresult").val();
$("#results span").html(dieRoll);
});
</script>
</head>
<body>
<div data-role="page" id="valued" data-theme='a'>
<div data-role="header" data-header-theme='a'>
<a data-icon="back" data-rel="back" back-btn="true">Back</a>
<h1>Value</h1>
<a data-icon="home" href="index.html" data-iconpos="notext">Home</a>
</div>
<div data-role="content" data-theme='a'>
<form id="rollform">
<select id="dieresult" name="dieresult">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
Submit
</form>
</div>
</body>
</html>
And here's the code for valuedresult.html:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Value Result</title>
<script>
$(document).on('pageshow', function(event) {
var url = $.url(document.location);
var arg1 = url.param("arg1");
$("#results span").html(arg1);
});
</script>
</head>
<body>
<div data-role="page" id="valueresult" data-theme='a'>
<div data-role="header" data-header-theme='a'>
<a data-icon="back" data-rel="back" back-btn="true">Back</a>
<h1>Value Result</h1>
<a data-icon="home" href="index.html" data-iconpos="notext">Home</a>
</div>
<div data-role="content" data-theme='a'>
<div id="results">Result: <span></span>
</div> <!-- results -->
</div>
</body>
</html>
As I said, it works fine on a desktop browser, but nothing happens on the iPhone emulator when I click "Submit".
I've played around with this for quite a while, referring to other posts, documentation, etc... but I just can't seem to get it working. Hopefully I'm just missing something silly.
Any help is appreciated. Thank you very much in advance!
EDITED: I've noticed this piece of code $.url. This is not part of jQuery or jQuery Mobile. You're missing the Purl JavaScript URL parser plugin. You should add it in the first page's head tag.
Below you can find some fixes related to the code you've posted. I have removed the code which refers to the missing Purl JavaScript URL parser plugin as well.
In the first page, attaching the click event handler on the document element is enough. You don't need to include it inside a pageinit event handler. Moreover instead of using return false; it is better to use event.preventDefault() in order to prevent the default behavior of the event. I have removed some unnecessary code as well.
In the second page, I have modified your script and put it inside the jQM page. The reason is that when a jQM page is loaded through Ajax, the script inside the head tag are not loaded. An alternative solution would be to load this script on the first page's load.
I have modified your example as following:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Value Submit</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css">
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type='text/javascript'>
$(document)
.on('click', '#submitroll', function (e) {
e.preventDefault();
var dieRoll = $("#dieresult")
.val();
$.mobile.changePage('valuedresult.html', {
data: {
arg1: dieRoll
}
});
});
</script>
</head>
<body>
<div data-role="page" id="valued" data-theme='a'>
<div data-role="header" data-header-theme='a'>
<a data-icon="back" data-rel="back" back-btn="true">Back</a>
<h1>Value</h1>
<a data-icon="home" href="index.html" data-iconpos="notext">Home</a>
</div>
<div data-role="content" data-theme='a'>
<form id="rollform">
<select id="dieresult" name="dieresult">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
Submit
</form>
</div>
</body>
</html>
valuedresult.html:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Value Result</title>
</head>
<body>
<div data-role="page" id="valueresult" data-theme='a'>
<div data-role="header" data-header-theme='a'>
<a data-icon="back" data-rel="back" back-btn="true">Back</a>
<h1>Value Result</h1>
<a data-icon="home" href="index.html" data-iconpos="notext">Home</a>
</div>
<div data-role="content" data-theme='a'>
<div id="results">Result: <span></span>
</div>
<!-- results -->
</div>
<script>
$(document)
.one('pageshow', '#valueresult', function (event) {
var parameters = $(this)
.data("url")
.split("?")[1];
parameter = parameters.replace("arg1=", "");
$("#results span")
.html(parameter);
});
</script>
</div>
</body>
</html>
I hope that helps.

Checkbox onclick and onchange event called twice, please see simple example

If i comment out the jquery.mobile...js file, this works fine, with it included, everytime i click the checkbox, the onclick event fires twice. Same is true for onchange event. Any ideas?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<script>
function tester() { alert("I get called twice on click"); }
</script>
<input id="abc" name="myCheckbox" onchange="tester()" type="checkbox" value="true" />
<label for="myCheckbox">Click me</label>
</body>
</html>
This is by design, since both events are happening. See example: http://jsfiddle.net/Twisty/T3qmG/
HTML:
<html>
<head>
<title>Checkbox Test</title>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h2>Checkbox Test</h2>
</div>
<div data-role="content">
<input type="checkbox" id="checkbox-choice-1" />
<label for="checkbox-choice-1">Click me</label>
</div>
</div>
</body>
</html>
JQuery:
$(document).ready(function(){
$("#checkbox-choice-1").click(function(){
alert("Click event triggerd.");
});
$("#checkbox-choice-1").change(function(){
alert("Change event triggerd.");
});
});
I would advise separating your script code if possible. You can a function to one or both events.
Your markup is malformed. The <label> tag points to a non-existent id. It points to "myCheckbox" but the id of your input tag is "abc". This change fixes your issue and the markup is correctly enhanced.
<input id="abc" name="myCheckbox" onchange="tester()"
type="checkbox" value="true" />
<label for="abc">Click me</label>

touchOverflowEnabled: true leads to problems with a dialog on iPad

I want to open a dialog in combination with touchOverflowEnabled: true.
The problem is the following:
The dialog is coming up properly but after a couple of milliseconds, the background below the dialog turns from black into white; the page seems to shrink.
Furthermore, the checkboxes on the main page are smaller; they do not fit the complete page from left to right.
If I do not use touchOverflowEnabled: true everything works well.
Any ideas, how to solve this problem??
Here's my complete sample code (the html-tags are missing):
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon" href="images/icon.png" />
<link rel="apple-touch-startup-image" href="images/tablet_startup.png">
<link rel="stylesheet" href="css/black-tie/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" href="css/jquery-mobile/jquery.mobile-1.0.css" />
<link rel="stylesheet" href="css/styles.css" />
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function(){
$.extend( $.mobile , {
touchOverflowEnabled: true,
defaultDialogTransition: 'pop',
orientationChangeEnabled: false
})
});
</script>
<script type="text/javascript" src="js/jquery.mobile-1.0.js"></script>
</head>
<body>
<!-- Begin objective page -->
<section id="questions_objectives" data-role="page">
<header data-role="header" data-position="fixed">
<h1>Goals</h1>
</header><!-- /header -->
<div data-role="content">
<form id="f_objectives">
<h3>Personal Goals</h3>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<input type="checkbox" name="o_1" id="o_1">
<label for="o_1">Goal 1</label>
<input type="checkbox" name="o_2" id="o_2">
<label for="o_2">Goal 2</label>
<input type="checkbox" name="o_3" id="o_3">
<label for="o_3">Goal 3</label>
</fieldset>
</div>
</form>
</div><!-- /content -->
<footer data-role="footer" data-id="pluginFooter" data-position="fixed">
<div align="center" data-role="controlgroup" data-iconpos="top" data-type="horizontal">
Abmelden
</div>
</footer><!-- /footer -->
</section><!-- /page -->
<!-- End objective page -->
<!-- Begin logout page -->
<section id="logout_panel" data-role="dialog">
<header data-role="header">
<h1>Logout</h1>
</header><!-- /header -->
<div id="section_logout" name="section_logout" data-role="content">
<h3>Would you like to receive emails?</h3>
<form id="logout_form">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<input type="checkbox" name="logout_yes" id="logout_yes" checked="checked" onchange="setLogoutCB('YES')">
<label for="logout_yes">Yes</label>
<input type="checkbox" name="logout_no" id="logout_no" onchange="setLogoutCB('NO')">
<label for="logout_no">No</label>
</fieldset>
</div>
</form>
</div><!-- /content -->
<footer data-role="footer">
<div id="btn_logout" align="center" data-role="controlgroup" data-iconpos="top" data-type="horizontal">
Logout
</div>
</footer><!-- /footer -->
</section>
<!-- End logout page -->
</body>
i would recommend u not to use touchOverflowEnabled anymore. It has its own issues and it wont even be there in jquery mobile from the version 1.1
its going to be deprecated.
there,
In my opinion all your problems come from the jQuery version that you have been using - 1.7
According to the JQM blog
Reminder: 1.0 supports jQuery core 1.6.4 only
Since 1.7 was just recently released and has some significant changes (and improvements), only 1.6.4 is officially supported at this time. We plan on adding 1.7 support when we release version 1.1.
When I use touchOverflowEnabled with 1.6.4 there seems to be no problems as you explained above.
There is still a small bug with iPad and touchOverflowEnabled - the dialog is only half page height but this is also easy fixed with single line of css
.ui-mobile [data-role="dialog"]{height: 100%;}
I hope all this is useful :)
Best Regards,
Mihail

Can't get dialog to open in Jquery mobile

When the proper value is selected I want to open the div with id="new_firm" in a modal dialog. I can't get the dialog to open. I know that the script get's executed since the alert pops up. Can anyone please tell me what's wrong here?
<!DOCTYPE html>
<html>
<head>
<title>FileReader Example</title>
<link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.0.css" />
<script type="text/javascript" charset="utf-8" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="js/phonegap-1.3.0.js"></script>
<script type="text/javascript" charset="utf-8">
function openNewFirmDialog() {
var selected = $("#select_firm option:selected");
var ddValue = selected.text();
if(ddValue === "Add a new company") {
//alert(ddValue);
$('#new_firm').dialog({modal:true});
}
}
</script>
</head>
<body>
<div data-role="page" id="add_details">
<div data-role="content">
<h2>Register hours</h2>
hei
<div data-role="fieldcontain">
<select id="select_firm" data-native-menu="false" onchange="openNewFirmDialog()">
<label for="select_firm" class="select">Select firm:</label>
<option data-placeholder="firm">Firm</option>
<option value="internal">Internal</option>
<option value="new_firm_option">Add a new company</option>
</select>
</div>
<input type="text" id="descritptionTxt" value="Description"/>
<div data-role="controllgroup" data-type="horizontal">
<input type="range" id="number_of_hours" min="0" max="24" step="0.25" value="0" />
<input type="range" id="number_of_minutes" min="0" max="24" step="0.25" value="0" />
</div>
</div>
<div data-role="footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li>Overview</li>
<li>Add hours </li>
<li>Settings</li>
</ul>
</div>
</div>
</div>
<div data-role="page" id="new_firm">
<h2>Add a new firm</h2>
<textarea id="the_new_firm" value="New firm"/>
</div>
</body>
I think you need to add reference to jQuery UI if you want to use dialogs. Available for download here: http://jqueryui.com/demos/dialog/

Resources