我无法验证克隆字段集的输入。我尝试在每次克隆后重新初始化表单验证程序,并为每个克隆的输入添加.rules(' add' ... required:true),但验证仍然失败。任何帮助将不胜感激......
HTML:
<fieldset class="individual-award">
<legend>Individual Award - Received</legend>
<p class="left">
<label for="individual-award-organization">Organization Granting Award</label>
<input type="text" name="individual-award[organization][]" class="required" />
<label for="individual-award-name">Name of Award</label>
<input type="text" name='individual-award[name][]' class="required" />
<label for="individual-award-city-state">City, State</label>
<input type="text" name="individual-award[city-state][]" class="required" />
<label for="individual-award-date">Date Received</label>
<input type="text" name="individual-award[date][]" class="date-picker required" />
</p>
</fieldset>
jQuery的:
jQuery(document).ready(function() {
var addBtn = jQuery('<input type="button" value="Add Entry" class="add-entry" style="position: absolute; right: 5px; bottom: 5px;" />');
jQuery('fieldset[class]').not('.team-award, .bibliography, .interests, .grants-education, .grants-research, .presentations').append(addBtn);
jQuery('.add-entry, .delete-entry').bind('click', function(){
if ( jQuery(this).attr('class') == 'add-entry' ) {
var clone = jQuery(this).closest('fieldset').clone(true);
var inpts = clone.find(':input:not(:button)');
jQuery(this).closest('fieldset').find('.add-entry').attr({'class':'delete-entry', 'value': 'Delete Entry'});
inpts.val('');
clone.find('input.date-picker').removeClass('hasDatepicker').removeAttr('id').datepicker({
prevText: '',
nextText: '',
changeMonth: true,
changeYear: true,
yearRange: '1975:2024',
dateFormat: 'MM d, yy',
constrainInput: false
});
clone.insertAfter('fieldset:last');
} else {
jQuery(this).closest('fieldset').remove();
}
});
jQuery('#reaims-update-form').validate({
errorPlacement: function(error, element){
return true;
},
ignore:":hidden"
});
});