我试图将元素动态添加到 yii 1.1 TbActiveForm。我尝试了两种方法来做到这一点,但在验证方面失败了。请看下面我的方法。
方法一#克隆元素;修改id
这就是我创建表单的方式
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'form-name',
'enableClientValidation' => true,
'clientOptions' => array(
'validateOnSubmit'=>true
),
'action' => $this->createUrl('test/manageusers')
));
单击“添加更多”按钮时,此脚本将复制元素
$('#add-comp-user').on('click', function(){
// template
var html = $('.add-comp-users-wrapper').first().clone();
// next element index
var next_index = // find last element's index attribute
// update element id's
html.find(':input').each(function(){
// update name
// update id
});
// insert to DOM
});
方法 2 #Ajax 方法 在这里,单击“添加更多”按钮,我将呈现具有新 id 的表单元素并插入到 DOM
这两种方法都未能通过验证。如何在 Yii 验证中包含新添加的元素?