ive been studying this link but i cant figure out how he resize the option box and i want to know how to resize option box text box buttons etc. in jquery mobile but i cant find a way to resize them i also want to know if it is possible to impelement ajax on a jquery mobile that uses internal pages?and also how can you set the distance between label and textbox?here is the code of the link
http://jsfiddle.net/HwFFU/1/
<div data-role="page">
<div data-role="header">
<h1>My Title</h1>
</div><!-- /header -->
<div data-role="content">
<form method="post" action="processForm.php">
<li data-role="fieldcontain">
<label for="children" class="select">Number of Kids</label>
<select name="children" id="children" data-mini="true">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</li>
<div id="kidsFields"></div>
</form>
</div><!-- /content -->
</div>
var html = '';
$('#children').on('change', function() {
children = $(this).val();
html = '';
for (var i = 0; i < children; i++) {
html += '<label>Name</label><input type="text" id="textName' + i + '" name="child' + i + 'Name" /><label>Age</label><input type="text" name="child' + i + 'Age" id="textAge' + i + '" />';
}
$('#kidsFields').html(html);
$('#kidsFields').append('<input type="submit" value="Submit" />');
$('.ui-page').trigger('create');
});
I have updated your fiddle: http://jsfiddle.net/ezanker/HwFFU/20/ Here each Name/Age input field pair is on a single line with the inputs resized and the distance between label and input set.
When inserting the form elements, you can surround them with a div set to a data-role of fieldcontain (this also automatically stacks the elements on narrow screens):
for (var i = 0; i < children; i++) {
html += '<div data-role="fieldcontain"><label>Name</label><input type="text" id="textName' + i + '" name="child' + i + 'Name" /><label>Age</label><input type="text" name="child' + i + 'Age" id="textAge' + i + '" /></div>';
}
Then use CSS to set input field size and distance between label and input e.g.
#kidsFields .ui-input-text{
width: 80px;
margin: 1em;
}
And, yes you can use AJAX with jQM internal pages. Perhaps you should create a separate and more specific question about that...
Related
I use jQuery mobile 1.4.5 in my project.
I create dynamically table with buttons by click. When table created the JQM style isn't apply.
Here is my HTML code:
<div data-role="page" id="page1">
<div data-role="header">
<h1>My page</h1>
</div>
<div data-role="content" class="ui-content">
<button onclick="CretaeTable()">Cretate table</button>
<div id="vectorLayerslist"></div>
</div>
Here is JavaScript code:
function CretaeTable(){
var vectorLayersList = $('#vectorLayerslist');
var arr = [{id:'124',Title:'qqq'},
{id:'589',Title:'www'},
{id:'45',Title:'eee'},
{id:'567',Title:'rrr'}]
var table = layersListTable(arr);
vectorLayersList.append(table);
}
function layersListTable(layers) {
// build the table
var frame = '<fieldset style="border: solid 1px #6b6b6b;">';
var smallHeader = '<legend>title</legend>';
var content = frame + smallHeader + '<table data-role="table" id="layersListEditable" data-mode="columntoggle:none" class="ui-responsive"><thead><tr></tr></thead>';
$.each($(layers), function () {
// we'll store the ID in HTML5 data-attribute for later
content += '<tr>';
// give classes to your buttons for later
content += '<td><button data-mini="true" data-inline="true" data-icon="edit" data-theme="b" type="button" class="edit">Edit</button></td>';
content += '<td><button data-mini="true" data-inline="true" data-icon="delete" data-theme="b" type="button" class="delete">Delete</button></td>';
content += '<td style="vertical-align: inherit;">' + this.Title + '</td>';
content += '</tr>';
});
content += '</table>';
content += '</fieldset>'
return content;
}
Here is JSFIDDLE.
Why JQM style isn't apply?
You jist only need to rebuild the table, and then maybe update the layout of the whole page content:
... your dynamic table creation
vectorLayersList.append(table);
// add this:
$("#layersListEditable").table().table("rebuild");
$(".ui-content").trigger("updatelayout");
Please, note: you may also adjust the button markup, something like this:
content += '<td><button class="ui-btn ui-mini ui-btn-inline ui-btn-icon-left ui-icon-edit">Edit</button></td>';
content += '<td><button class="ui-btn ui-mini ui-btn-inline ui-btn-icon-left ui-icon-delete">Delete</button></td>';
Here is your updated Fiddle: http://jsfiddle.net/aJUy8/105/
I am atempting to clone a div (multiple times) and add increments so I can parse the results into a database using XML. I only want to clone the form section not the data entered. The Div I am cloning has 3 selects and 2 radios (all of which when added need to be empty).
HTML
<div id="Template1" class="template">
<div class="_100">
<div class="_25"> <fieldset>
<label class="label_analysis" for="analysis">Analyte:</label>
<select class="select_analyte" name="analysis" id="analysis">
<option value="">Select</option>
<option value="TN">TN</option>
<option value="TP,NO2+3">TP,NO2+3</option>
</select> </fieldset></div>
<div data-role="controlgroup" class="_13">
<label><input type="checkbox" data-mini="true" name="Filtered" id="Filtered" value="True">
0.45u Filtered</label>
<label><input type="checkbox" data-mini="true" name="Dup" id="Dup" value="True">
Field Dup</label></div>
<div class="_25"><fieldset>
<label class="label_preserve" for="preserve">Preserved</label>
<select class="select_preserve" name="preserve" id="preserve">
<option value="">Select</option>
<option value="HNO3">HNO₃</option>
<option value="H2SO4">H₂SO₄</option>
</select></fieldset></div>
<div class="_20"> <fieldset>
<label class="label_cool" for="cool">Cooled</label>
<select class="select_cool" name="cool" id="cool">
<option value="">Select</option>
<option value="Ice">Ice</option>
<option value="Frozen">Frozen</option>
<option value="None">None</option>
</select>
</fieldset></div>
<div class="_13">
Add Analyte
Remove</div>
</div>
</div>
<div id="place" class="place"></div>
I have tried two different scripts
This script works as I want to hide the remove button on the original div and only have it appear on the cloned but it doesn't increment.
(function($){
var Template = $('.Template');
var count = 0;
$('.removeNew').hide().on('click', function(e) {
e.preventDefault();
$(this).closest('.Template').remove();
});
$('a.showNew').on('click', function(e) {
e.preventDefault();
var clone = Template.clone(true, true).insertAfter("#place").find('.removeNew').show().end();
});
})(jQuery);
and this one which increments but doesn't hide the remove button
$('#showNew').click(function() {
var num = $('.template').length,
newNum = new Number(num + 1),
newElem = $('#Template' + num).clone(true, true).attr('id', 'Template' + newNum).appendTo('#place');
newElem.find('.analysis').attr('id', 'ID' + newNum + '_analysis').attr('name', 'ID' + newNum + '_analysis').val();
newElem.find('.preserve').attr('id', 'ID' + newNum + '_preserve').attr('name', 'ID' + newNum + '_preserve').val();
newElem.find('.cool').attr('id', 'ID' + newNum + '_cool').attr('name', 'ID' + newNum + '_cool').val();
$('#Template'+ num).after(newElem);
});
})
I am wondering if there is some way to combine them...
I am also having issues as no matter what I seem to try the original div becomes the clone, complete with remove button, while what should be the original div can be changed.
I believe the simplest approach is to have an original copy of the template hidden and base all clones off of that. This fiddle demonstrates this approach.
(function ($) {
var Template = $('#Template');
var count = 0;
var nextId = 0;
Template.find('.removeNew').on('click', function (e) {
e.preventDefault();
$(this).closest('.template').remove();
count--;
});
function cloneTemplate(removable) {
var clone = Template.clone(true, true);
clone.attr('id', clone.attr('id') + nextId);
clone.find('label[for]').each(function( index ) {
var elem = $(this);
elem.attr('for', elem.attr('for') + nextId);
});
clone.find('select, input').each(function( index ) {
var elem = $(this);
elem.attr('id', elem.attr('id') + nextId);
elem.attr('name', elem.attr('name') + nextId);
});
if (!removable) {
clone.find('.removeNew').remove();
}
clone.insertBefore("#addNew").removeClass('hide');
count++;
nextId++;
}
// Create First Analyte and delete the remove button.
cloneTemplate(false);
$('a.showNew').on('click', function (e) {
e.preventDefault();
cloneTemplate(true);
return false;
});
})(jQuery);
It didn't make sense to have the Add New button inside the template so I moved it outside. All new clones are added before the Add New button.
You should notice in the script above that the first element is created by cloning the Template. Then new elements are created calling the same clone function when the Add New button is clicked.
Note: This solution does not include updating element id or name attributes. Something that you almost certainly want to do.
I am developing android app using Jquery Mobile.
I am having some problem with tablesorter plugin with pager.
Here is my HTML page
<div id="mainPager" class="pager">
<form>
<div class="ui-grid-d">
<div class="ui-block-a"><input type="button" data-inline="true" data-mini="true" value="<<" class="first" /></div>
<div class="ui-block-b"><input type="button" data-inline="true" data-mini="true" value="<" class="prev" /></div>
<div class="ui-block-c"><input type="text" data-inline="true" data-mini="true" class="pagedisplay"/></div>
<div class="ui-block-d"><input type="button" data-inline="true" data-mini="true" value=">" class="next" /></div>
<div class="ui-block-e"><input type="button" data-inline="true" data-mini="true" value=">>" class="last" /></div>
</div>
<select class="pagesize">
<option selected="selected" value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
</select>
</form>
</div>
<table class="myTable" id="dataTable" >
<thead>
</thead>
<tbody>
</tbody>
</table>
This is my jquery code.
$(document).on('pagebeforecreate', '#main' ,function(){
fillRoTable() ;
});
function fillRoTable()
{
var html = '';
for (var key=0, size= 1; key<size;key++) {
html += '<tr><th>'
+ "Ticket #"
+ '</th><th>'
+ "Action"
+ '</th></tr>';
}
$('#dataTable thead').append(html);
$.ajax({url: "h**p://xyz.com/test/info?client=ig&docId=2313",
dataType: "jsonp",
async: true,
success: function (result) {
var html1 = '';
for (var key=0, size=25; key<size; key++) {
html1 += '<tr><td>'
+ key
+ '</td><td>'
+ (size-key)
+ '</td></tr>';
}
$('#dataTable tbody').append(html1);
$("#dataTable").tablesorter()
.tablesorterPager({container: $("#MainPager"), positionFixed: false});
},
error: function (request,error) {
alert('Network error has occurred please try again!');
}
});
}
Now my problem is that when main page loads everything is looking fine but if I tap on one of the heading to sort the column then I table becomes empty.
Can anyone suggest me what am I doing wrong here.
Thanks
It looks like we solved this issue by updating the pager script from the original plugin (v2.0.5) to the one from my fork of tablesorter.
My real desire is to create a selectable tree for JQM (with 3 values for each element). I tried to do with nested collapsible divisions, and this works fine. But when I tried to add the 3 radios on each collapsible bar, the events don't fire properly.
I think the collapse/expand event hooks the click event of the radios. The effect is when you click the radios, the collapsible is expanded and the radio is not checked.
<div data-role="collapsible" data-theme="b" data-content-theme="d" id="accordion1">
<h3>60
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true" >
<input type="radio" name="selcrit-CLP-60" id="selcrit-CLP-60-asign" value="60-asign">
<label for="selcrit-CLP-60-asign">Asign</label>
<input type="radio" name="selcrit-CLP-60" id="selcrit-CLP-60-omit" value="60-omit">
<label for="selcrit-CLP-60-omit">Omit</label>
<input type="radio" name="selcrit-CLP-60" id="selcrit-CLP-60-nothing" value="60-nothing">
<label for="selcrit-CLP-60-nothing">Nothing</label>
</fieldset>
</h3>
<div stylee="margin: 0 10px;">
Content for 60
</div>
Here is the jsfiddle with the example: http://jsfiddle.net/Hz8Ef/
Any idea? Can I do in other way?
Solved!
$(document).ready(function() {
$("div .ui-radio").click(
function(e){
var radioId = $(this).children(":first").attr('name');
$('input[name=' + radioId + ']').checkboxradio( "refresh" );
e.stopPropagation();
}
);
});
Here the complete solution: http://jsfiddle.net/VuaQg/1/
I managed to style my checkboxes in JQuery as I wanted them to look:
var content = '<fieldset data-role="controlgroup" class="ui-corner-all ui-controlgroup ui-controlgroup-vertical">' +
'<div class="ui-controlgroup-controls">' +
'<div class="ui-checkbox">' +
'<input type="checkbox" name="checkbox-1a" id="checkbox-1a" class="custom">' +
'<label for="checkbox-1a" data-corners="true" data-shadow="false" data-iconshadow="true" data-wrapperels="span" data-theme="c" class="ui-btn ui-btn-icon-left ui-corner-top ui-checkbox-on ui-btn-up-c">' +
'<span class="ui-btn-inner ui-corner-top"><span class="ui-btn-text">Food</span><span class="ui-icon ui-icon-shadow ui-icon-checkbox-on"> </span></span></label></div>' +
'<div class="ui-checkbox">' +
'<input type="checkbox" name="checkbox-4a" id="checkbox-4a" class="custom">' +
'<label for="checkbox-4a" data-corners="true" data-shadow="false" data-iconshadow="true" data-wrapperels="span" data-icon="checkbox-off" data-theme="c" class="ui-btn ui-btn-up-c ui-btn-icon-left ui-checkbox-off ui-corner-bottom ui-controlgroup-last">' +
'<span class="ui-btn-inner ui-corner-bottom ui-controlgroup-last"><span class="ui-btn-text">Sun Chips</span><span class="ui-icon ui-icon-checkbox-off ui-icon-shadow"> </span></span></label></div>' +
'</div></fieldset>';
The result is static (no action or status change when clicking the button).
How do I get them to act as a normal checkbox, changing its checked status when clicked?
Thank you!
I suppose you append your html string to the div which has the id myCheckBoxes
e.g: <div id="myCheckBoxes"></div>
try as below
$('#myCheckBoxes').html(content);
$('#myCheckBoxes').trigger("create");
jQuery Mobile is not only styling elements but also adds some event handling and class/attributes switching (similar for JUI, but you have JQM in a tag). So you either need to add this behavior on your own or insert standard elements before JQM starts parsing or insert standard elements and make JQM parse them again.
To make JQM re-render mobile page markup you need to call something like this:
$jqueryElement.trigger("create");
Where $jqueryElement is e.g.:
$jqueryElement = $('#elementId');
EDIT:
In another words you shouldn't use classes like ui-checkbox. You should add a simple input with label and a fieldset like this:
<fieldset data-role="controlgroup" data-type="vertical">
<input id="foo1" name="foo" type="checkbox"><label for="foo1">Option 1</label>`
<input id="foo2" name="foo" type="checkbox"><label for="foo2">Option 2</label>`
</fieldset>