I am cloning a form in jQuery mobile and the cloned form elements do not seem to work. IE the select lists do not change value, you cannot slide the range sliders.
I'm trying to use the following code to clone a form and increment the name and id values on each instance of the cloned form.
function newObservation() {
var len = $('.observation').length;
var titleLen = $('.observation').length + 2;
var $html = $('.observationTemplate').clone();
$('.observationTitle:eq(0)').text("Observation - " + titleLen);
$html.find('[name=audit-observation-category]').eq(0).attr({name:"audit-observation-category" + len, id:"audit-observation-category" + len});
$html.find('[name=audit-observation-notes]').eq(0).attr({name:"audit-observation-notes" + len, id:"audit-observation-notes" + len});
$html.find('[name=audit-observation-recommendation]').eq(0).attr({name:"audit-observation-recommendation" + len, id:"audit-observation-recommendation" + len});
$html.find('[name=audit-observation-severity]').eq(0).attr({name:"audit-observation-severity" + len, id:"audit-observation-severity" + len});
$html.find('[name=audit-observation-person]').eq(0).attr({name:"audit-observation-person" + len, id:"audit-observation-person" + len});
$html.find('[name=audit-observation-date]').eq(0).attr({name:"audit-observation-date" + len, id:"audit-observation-date" + len});
return $html.html();
}
$(document).on('pageinit', function(){
$('<div/>', {
'class' : 'observation', html:newObservation()
}).appendTo('#auditContainer');
$('#auditObservationButton').click(function() {
$('<div/>', {
'class':'observation', html:newObservation()
}).hide().appendTo('#auditContainer').slideDown('slow');
});
$('#auditForm').on('click', '.close', function(){
$(this).parent().fadeOut();
});
});
Here is a fiddle, which outlines the code but doesn't work due to jQM erros in the library itself (or so says jsfiddle) http://jsfiddle.net/FL398/
Here is an example of what Im encountering http://dirtybirddesignlab.com/FireSafe/audit.html#auditForm if you click 'Add Observation' the form clones, increments the name and id attributes of the elements correctly but they are in accessible.