删除JavaScript验证中的函数

时间:2014-02-24 08:43:07

标签: javascript php jquery yii

我是Yii的新手。我在视图中做了一个JavaScript验证部分。我正在向客户添加一个新的主机,服务ID,如果我点击添加更多,它再次给我两个字段添加另一个,但删除功能在这里不起作用。并且假设如果我在添加更多字段后在字段中输入空白值,那么它必须返回一些错误信息,怎么做,请帮帮我。提前谢谢。

我的观点:

<div id="content">
<div class="innerLR">
<div class="row-fluid">
<div class="form">

<?php
echo $id = $id;
$form = $this->beginWidget ( 'CActiveForm', array (
        'id' => 'nimsoft-host-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // There is a call to performAjaxValidation() commented in generated controller code.
        // See class documentation of CActiveForm for details on this.
        'enableAjaxValidation' => false 
) );
?>

    <fieldset>
        <legend>Customer Host Information:</legend>
            <?php echo $form->errorSummary($model); ?>
                <div id="add_details">
                <tr>
                    <td style="text-align: left;" class="tdSpan">
                            <?php echo $form->labelEx($model, 'host_name'); ?>
                       </td>
                <td class="tdSpan">
                            <div class="row">
                                <?php echo $form->textField($model, 'host_name', array('size' => 60, 'maxlength' => 88)); ?>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left;" class="tdSpan">
                            <?php echo $form->labelEx($model, 'host_serviceid'); ?>
                        </td>
                <td class="tdSpan">
                            <div class="row">
                                <?php echo $form->textField($model, 'host_serviceid', array('rows' => 6, 'cols' => 50)); ?>
                            </div>
                       </td>
                   </tr>
               </div>
               <tr class="tdSpan">
                   <td></td>
                   <td>
                       <div>
                           <div class="row">
                               <?php //echo $form->labelEx($model,'prod_avl_date'); ?>
                                   <?php
                                       $this->widget ( 'zii.widgets.jui.CJuiDatePicker', array (
                                                        'name' => 'Products[prod_avl_date]',
                                                        // additional javascript options for the date picker plugin
                                                        'options' => array (
                                                                        'showAnim' => 'fold',
                                                                        'dateFormat' => 'yy/mm/dd' 
                                                        )
                                                        ,
                                                        'htmlOptions' => array (
                                                                        'style' => 'height:20px;' 
                                                        ) 
                                        ) );
                                        ?> 
                                        <?php //echo $form->error($model,'prod_avl_date'); ?>
                          </div>
                          <div class="row">
                              <?php //echo $form->labelEx($model,'prod_end_date'); ?>
                              <?php
                                    $this->widget ( 'zii.widgets.jui.CJuiDatePicker', array (
                                                    'name' => 'Products[prod_end_date]',
                                                    // additional javascript options for the date picker plugin
                                                    'options' => array (
                                                                    'showAnim' => 'fold',
                                                                    'dateFormat' => 'yy/mm/dd' 
                                                    )
                                                    ,
                                                    'htmlOptions' => array (
                                                                    'style' => 'height:20px;' 
                                                    ) 
                                    ) );
                                    ?>
                               <?php //echo $form->error($model,'prod_end_date'); ?>
                          </div>
                      </div> 
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <div class="row buttons">
                          <h2>
                              <a href="#" id="addHost">Add Another Host</a>
                          </h2>
                      <div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
                      <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('onclick' => 'return checkForm();')); ?>
                  </div>
              </td>
          </tr>
      </tbody>
 </table>
    <?php $this->endWidget(); ?>
    </fieldset>
</div>
</div>
</div>
</div>

<div id="footer" class="hidden-print">
    <?php $this->renderPartial('application.views.layouts._footer_inc'); ?>
</div>


<script>
    $('#addHost').click(function()
    {
        $('#add_details').append('<?php echo $form->labelEx($model, 'host_name'); ?>
        <?php echo $form->textField($model, 'host_name', array('size' => 60, 'maxlength' => 88)); ?>
        <?php echo $form->labelEx($model, 'host_serviceid'); ?>
        <?php echo $form->textField($model, 'host_serviceid', array('rows' => 6, 'cols' => 50)); ?><a href="#" id="remove">REMOVE</a>');
        $("remove").on("click",".removeclass", function(e){ //user click on remove text
            if( x > 1 ) {
                    $(this).parent('add_details').remove(); //remove text box
                    x--; //decrement textbox
            }
            return false;
        }) 
    });
</script>

0 个答案:

没有答案