Cloning Form elements - select and range inputs

Cloning Form elements - select and range inputs

I am having a hell of a time cloning a form in jQuery Mobile 1.3.2 and jQuery 1.9.1. Originally all expandable and range inputs weren't working (were visible but had no functionality) when cloned, now they are acessible but duplicated - a select nested inside a select


  1. I have the following markup: 
  2. <div data-role="page" id="auditForm" data-theme="a">
  3.     <!--Observation-->
  4.                 <div class="observationTemplate">
  5.                     <h4 class="observationTitle">Observation - 1</h4>
  6.                     <a href="#" data-role="button" data-icon="delete" data-iconpos="notext" data-inline="true" data-theme="b" class="close">close</a>
  7.                     <div data-role="fieldcontain">
  8.                         <label for="audit-observation-category" class="ui-hidden-accessible select">Observation Category</label>
  9.                         <select name="audit-observation-category" id="audit-observation-category" data-theme="e" data-corners="false">
  10.                             <option value="" selected>Observation Category</option>
  11.                             <option value="Site">Site</option>
  12.                             <option value="Incident">Incident</option>
  13.                             <option value="NearMiss">Near Miss</option>
  14.                         </select>
  15.                     </div>

  16.                     <div data-role="fieldcontain">
  17.                         <label class="ui-hidden-accessible" for="audit-observation-notes">Notes</label>
  18.                         <textarea cols="40" rows="8" name="audit-observation-notes" id="audit-observation-notes" class="notes" placeholder="Notes" maxlength="140"></textarea>
  19.                     </div>

  20.                     <div data-role="fieldcontain">
  21.                         <label class="ui-hidden-accessible" for="audit-observation-recommendation">Recommendation</label>
  22.                         <textarea cols="40" rows="8" name="audit-observation-recommendation" id="audit-observation-recommendation" class="notes" placeholder="Recommendation" maxlength="140"></textarea>
  23.                     </div>
  24.                     <!-- not working for some reason -->
  25.                     <div data-role="fieldcontain">
  26.                         <label for="audit-observation-severity" data-theme="e">Severity</label>
  27.                     </div>

  28.                     <div data-role="fieldcontain">
  29.                         <input type="range" name="audit-observation-severity" id="audit-observation-severity" value="15" min="15" max="180" step="15" data-hilight="true" data-theme="d">
  30.                     </div>

  31.                     <div data-role="fieldcontain">
  32.                         <label for="audit-observation-person" class="ui-hidden-accessible select">Observation Person</label>
  33.                         <select name="audit-observation-person" id="audit-observation-person" data-theme="e" data-corners="false">
  34.                             <option value="" selected>Observation Person</option>
  35.                             <option value="Jim">Jim</option>
  36.                             <option value="Bob">Bob</option>
  37.                             <option value="Gary">Gary</option>
  38.                         </select>
  39.                     </div>

  40.                      <div data-role="fieldcontain">
  41.                         <label class="ui-hidden-accessible" for="audit-observation-date">Date</label>
  42.                         <input type="date" name="audit-observation-date" id="audit-observation-date" placeholder="Date" value="">
  43.                     </div>
  44.                 </div><!--/observation-->
  45.                 <div id="auditContainer"></div>

  46.                 <div data-role="controlgroup" data-type="horizontal" data-theme="d">
  47.                     <a href="#" id="auditObservationButton" data-role="button" data-icon="plus" data-iconpos="right" data-inline="true" data-theme="b">Add Observation</a>
  48.                 </div>
  49. </div>

  50. and the following jQuery
  51. function newObservation() {
  52. var len = $('.observation').length;
  53. var titleLen = $('.observation').length + 2;
  54. var $html = $('.observationTemplate').clone();

  55. $('.observationTitle:eq(0)').text("Observation - " + titleLen);
  56. $html.find('[name=audit-observation-category]').eq(0).attr({name:"audit-observation-category" + len, id:"audit-observation-category" + len});
  57. $html.find('[name=audit-observation-notes]').eq(0).attr({name:"audit-observation-notes" + len, id:"audit-observation-notes" + len});
  58. $html.find('[name=audit-observation-recommendation]').eq(0).attr({name:"audit-observation-recommendation" + len, id:"audit-observation-recommendation" + len});
  59. $html.find('[name=audit-observation-severity]').eq(0).attr({name:"audit-observation-severity" + len, id:"audit-observation-severity" + len});
  60. $html.find('[name=audit-observation-person]').eq(0).attr({name:"audit-observation-person" + len, id:"audit-observation-person" + len});
  61. $html.find('[name=audit-observation-date]').eq(0).attr({name:"audit-observation-date" + len, id:"audit-observation-date" + len});
  62. return $html.html();
  63. }
  64. $(document).on('pagebeforecreate', function(){
  65. $('<div/>', {
  66. 'class' : 'observation', html:newObservation()
  67. }).appendTo('#auditContainer');

  68. $('#auditObservationButton').click(function() {
  69. $('<div/>', {
  70. 'class':'observation', html:newObservation()
  71. }).hide().appendTo('#auditContainer').slideDown('slow');
  72. $('#auditContainer').trigger('create');
  73. $('select').selectmenu('refresh');
  74. });

  75. $('#auditForm').on('click', '.close', function(){
  76. $(this).parent().fadeOut();
  77. });
  78. });
I have a fiddle, but for some reason it doesn't like jqm 1.3.2 and have it on my dev server http://dirtybirddesign.com/dirtybirddesignlab.com/FireSafe/audit.html#auditForm


Any help would be much appreciated.
Kane Leins