Currently working on clone and datepicker using jquery. With my current code cloning was happening perfectly. In the clone div the datepicker was working but it was not working like original.
When the user click add more button it was cloning entire div perfectly with the dates but if i select the date textfield from the cloned div year and month dropdown not displaying.
When the user click add more button in the original Degree date it was showing the current date but in the clone it was not showing.
I have tried with all possibilites from my side I am not getting
I have tried added destroy for the datepicker still not working
Here is my jquery code
var i = 1;
$(document).on("click", ".edu_add_button", function() {
var i = $('.cloned-row1').length;
$(".cloned-row1:last").clone(true).insertAfter(".cloned-row1:last").attr({
'id': function(_, id) {
return id + i
},
'name': function(_, name) {
return name + i
}
}).end().find('[id]').val('').attr({
'id': function(_, id) {
return id + i
}
});
$(".cloned-row1:last").find(".school_Name").attr('disabled', true).val('');
$(".cloned-row1:last").find(".degree_Description").attr('disabled', true).val('');
$(".cloned-row1:last").find('.datepicker,.datepicker1').removeClass('hasDatepicker').datepicker();
i++;
return false;
});
$("#txt_Degdat").datepicker({
dateFormat: "mm-dd-yy",
changeMonth: true,
changeYear: true,
yearRange: '1900:2100'
}).on('change', function() {
if ($('#txt_Degdat').valid()) {
$('#txt_Degdat').removeClass('errRed');
}
// triggers the validation test on change
}).datepicker("setDate", "0");
$("#txt_Trsdat").datepicker({
dateFormat: "mm-dd-yy",
changeMonth: true,
changeYear: true,
yearRange: '1900:2100'
}).on('change', function() {
if ($('#txt_Trsdat').valid()) {
$('#txt_Trsdat').removeClass('errRed');
}
// triggers the validation test on change
});
$(document).on('click', ".btn_less1", function() {
var len = $('.cloned-row1').length;
if (len > 1) {
$(this).closest(".btn_less1").parent().parent().parent().remove();
}
});
Here is the HTML code
<div class="container-fluid cloned-row1">
<div class="row">
<div class="col-xs-6 col-sm-3 col-md-4 col-lg-3">
<label>School Name</label>
<br/>
<select class="slt_Field txt_schName" name="txt_schName[]">
<option value="">Please Select</option>
<option value="Emirates College of Technology- UAE">COL000001</option>
<option value="Al Khawarizmi International College- UAE">COL000002</option>
<option value="Syscoms College">COL000003</option>
<option value="Abounajm Khanj Pre-Uni Center">COL000004</option>
<option value="Advanced Placement">COL000005</option>
<option value="Al Buraimi College (Uni Clge)">COL000006</option>
<option value="Al-Ain Community College">COL000007</option>
<option value="AMA Computer College">COL000008</option>
<option value="Arab Academy for Bankg and Fin">COL000009</option>
<option value="ARABACDSCITECHMARTIMETRNS">COL000010</option>
<option value="Arapahoe Community College">COL000011</option>
</select>
</div>
<div class="col-xs-6 col-sm-3 col-md-4 col-lg-3">
<br>
<input type="text" class="ipt_Field school_Name" name="school_Name[]" disabled/>
</div>
<div class="col-xs-6 col-sm-3 col-md-4 col-lg-3">
<label><span class="text-error">*</span>High School Avg / CGPA</label>
<br/>
<input type="text" class="ipt_Field ipt_Havg" id="" name="ipt_Havg[]" />
</div>
<div class="col-xs-6 col-sm-3 col-md-4 col-lg-3">
<label><span class="text-error">*</span>Grade Type @</label>
<br/>
<select class="slt_Field ipt_grd" name="ipt_grd[]">
<option value="">Please Select</option>
<option value="n">100</option>
<option value="n1">4</option>
<option value="c">CHAR</option>
</select>
</div>
<input type="text" placeholder="MM/DD/YYYY" class="ipt_Field txt_Degdat" name="txt_Fdob" />
</div>
<button class="btn_less1 btn_right ">Less</button>
<button class="btn_more btn_right edu_add_button">Add More</button>
Here is the weave Link
Any suggestion please what I am doing wrong here.
I have tried all possibilities nothing was working any idea please