我有一个用 CActiveForm 创建的表单,HTML 输出是这样的
...
<tr>
<td><input class="span9" placeholder="Type in the seminar title" name="CvSeminar[0][title]" id="CvSeminar_0_title" maxlength="255" value="Some Value" type="text"> <span class="help-inline error" id="CvSeminar_0_title_em_" style="display: none"></span> </td>
<td><input class="span1" name="CvSeminar[0][yearIssued]" id="CvSeminar_0_yearIssued" maxlength="4" value="2009" type="text"> <span class="help-inline error" id="CvSeminar_0_yearIssued_em_" style="display: none"></span> </td>
<td><a href="#" class="removeSeminarRow"><i style="margin-top: 10px" class="icon-remove"></i></a></td>
</tr>
<tr>
<td><input class="span9" placeholder="Type in the seminar title" name="CvSeminar[1][title]" id="CvSeminar_1_title" maxlength="255" value="Some Value" type="text"> <span class="help-inline error" id="CvSeminar_1_title_em_" style="display: none"></span> </td>
<td><input class="span1" name="CvSeminar[1][yearIssued]" id="CvSeminar_1_yearIssued" maxlength="4" value="2006" type="text"> <span class="help-inline error" id="CvSeminar_1_yearIssued_em_" style="display: none"></span> </td>
<td><a href="#" class="removeSeminarRow"><i style="margin-top: 10px" class="icon-remove"></i></a></td>
</tr>
...
如您所见,我创建了一个区域,其中每行包含两个字段。我还创建了一个按钮,用户可以在其中添加新行。用户点击按钮时的 html 输出为:
<tr>
<td><input class="span9" placeholder="Type in the seminar title" name="CvSeminar[1000][title]" id="CvSeminar_1000_title" maxlength="255" type="text"><span class="help-inline error" id="CvSeminar_1000_title_em_" style="display: none"></span></td>
<td><input class="span1" name="CvSeminar[1000][yearIssued]" id="CvSeminar_1000_yearIssued" maxlength="4" type="text"><span class="help-inline error" id="CvSeminar_1000_yearIssued_em_" style="display: none"></span></td>
<td><a href="#" class="removeSeminarRow"><i style="margin-top: 10px" class="icon-remove"></i></a></td>
</tr>
当我创建一个新行并将其留空时,我的问题就开始了。服务器端的 Ajax 验证工作正常。Yii 用 json 响应新字段有错误。
{"CvSeminar_1000_title":["Title cannot be empty."],"CvSeminar_1000_yearIssued":["Year cannot be empty"]}
问题出在客户端。由于 yiiactiveform 对新添加的行一无所知,我如何更新 yiiactiveform 以包含新添加的字段?
谢谢