$('#contact-form').yiiActiveForm('add', {
id: 'address',
name: 'address',
container: '.field-address',
input: '#address',
error: '.help-block',
validate: function (attribute, value, messages, deferred, $form) {
yii.validation.required(value, messages, {message: "Validation Message Here"});
}
});
Так я же вам показал, как добавлять поля динамически. Вы вчитайтесь внимательнее.
вы хотите вынести в отдельный файл. скрипт с ActiveForm
$form = ActiveForm::begin([
'id' => $idForm,
'enableAjaxValidation' => true,
'validationUrl' => Url::toRoute(['/proposal/default/ajax-validate']),
]);
function initAddAndRemoveButtons() {
var bodyTag = $('body');
bodyTag.on("click", ".b-addFields", function() {
var el = $(this),
parent = el.parents('.b-cargoSizes:first');
var parentClone = parent.clone(),
oldInputIndex = parent.siblings('.b-cargoSizes').length,
newInputIndex = oldInputIndex + 1;
parentClone.find('input').each(function(index, value) {
var newName = $(value).attr('name').replace('[' + oldInputIndex + ']', '[' + newInputIndex + ']');
var newId = $(value).attr('id').replace('' + oldInputIndex + '', '' + newInputIndex + '');
$(value).attr({'name': newName, 'id': newId});
$(value).next('div').removeClass('help-' + oldInputIndex + '-block').addClass('help-' + newInputIndex + '-block').text('')
//console.log(value);
$(value).val('');
});
parentClone.find('.b-addFields, .b-removeFields').show();
parent.after(parentClone);
parent.find('.b-addFields').hide();
parent.find('.b-removeFields').show();
});
bodyTag.on("click", ".b-removeFields", function() {
var el = $(this),
parent = el.parents('.b-cargoSizes');
var siblings = parent.siblings('.b-cargoSizes');
parent.remove();
if(siblings.length == 1) {
siblings.find('.b-removeFields').hide();
siblings.find('.b-addFields').show();
}
else if(siblings.length > 1) {
siblings.last().find('.b-addFields').show();
}
});
}
Object { value: "ыв", error: ".help-block", encodeError: true, validateOnChange: true, validateOnBlur: true, validateOnType: false, validationDelay: 500, enableAjaxValidation: true, status: 1, cancelled: false, ещё 7… }
А чего Вы хотите этим добиться?