私のコードには、JS を介して追加の機能を実装したフィールド (たとえば、フィールド名はexampleField[] ) があります。各フィールドに Yii2 に必要な Validtorを実装したいと考えています。すでに各バリデータを使用していますが、機能していません。私の yii2 バージョンは 2.0.6 です。ありがとうございます
ここに私のJavaScriptコードがあります
var max_fields = 4; //maximum input boxes allowed
var wrapper = $(".addAmount"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var html = '';
var x = <?php echo $count ?>; //initlal text box count
$(add_button).click(function (e) { //on add input button click
html = '<div id="multipleRow' + x + '"><div class="fullwidth">';
html += '<div class="span4"><div class="control-group">';
html += '<label for="plandetail-planduration" class="control-label">Duration <span class="required">*</span></label>';
html += '<div class="controls"><div class="form-group field-plandetail-planduration required">';
html += '<input type="text" name="PlanDetail[planDuration][]" class="form-control" id="plandetail-planduration">';
html += '<div class="error"></div></div></div></div>';
html += '</div>';
html += '<div class="span4"><div class="control-group">';
html += '<label for="plandetail-plandurationtype" class="control-label">Duration Period<span class="required">*</span></label>';
html += '<div class="controls"><div class="form-group field-plandetail-plandurationtype">';
html += '<select name="PlanDetail[planDurationType][]" class="form-control" id="plandetail-plandurationtype">';
html += '<option value=""></option>';
html += '<option value="month">Month</option>';
html += '<option value="year">Year</option>';
html += '</select>';
html += '<div class="help-block"></div>';
html += '</div></div></div></div></div>';
html += '<div class="fullwidth">';
html += '<div class="span4"><div class="control-group">';
html += '<label for="plandetail-planamount" class="control-label">Amount <span class="required">*</span></label>';
html += '<div class="controls"><div class="form-group field-plandetail-planamount required">';
html += '<input type="text" name="PlanDetail[planAmount][]" class="form-control" id="plandetail-planamount">';
html += '<div class="error"></div>';
html += '</div></div>';
html += '</div></div>';
html += '<div class="span4"><div class="control-group">';
html += '<label for="plandetail-plandiscountamount" class="control-label">Discount Amount <span class="required">*</span></label>';
html += '<div class="controls"><div class="form-group field-plandetail-plandiscountamount required">';
html += '<input type="text" name="PlanDetail[planDiscountAmount][]" class="form-control" id="plandetail-plandiscountamount">';
html += '<div class="error"></div>';
html += '</div></div>';
html += '</div></div>';
html += '<div class="span4"><div class="control-group">';
html += '<label for="plandetail-plancurrency" class="control-label">Currency <span class="required">*</span></label>';
html += '<div class="controls"><div class="form-group field-plandetail-plancurrency required">';
html += '<select name="PlanDetail[planCurrency][]" class="form-control" id="plandetail-plancurrency">';
html += '<option value=""></option><option value="USD">USD</option><option value="EUR">EUR</option>';
html += '</select>';
html += '<div class="help-block"></div>';
html += '</div></div>';
html += '</div></div>';
html += '</div>';
html += '<div class="col-lg-4"><a href="javascript:void(0)" class="remove_field" id="' + x + '">Remove</a></div>';
html += '</div></div>';
e.preventDefault();
if (x < max_fields) { //max input box allowed
x++; //text box increment
$(wrapper).append(html); //add input box
}else{alert('You Can not add more than 4 Amount')}
});
$(wrapper).on("click", ".remove_field", function (e) { //user click on remove text
e.preventDefault();
// alert(this.id);
$("#multipleRow" + this.id).remove();
x--;
});