如何在master中添加Ajax验证,其中我有基于jqrelcopy的其他表的字段?

时间:2012-10-26 04:41:12

标签: yii yii-extensions

  
    

在母版页(_form)中我想保存三个字段

  
     
      
  1. 下拉
  2.   
  3. 文本框
  4.   
  5. 选项列表,如果选择了选项列表中的某个选项,我需要显示JQrelcopy,用户可以添加许多   使用JQrelcopy的值。存储在JQrelcopy中的值具有   保存在其他表中。

         

    现在问题是我想像字段一样给出AJAX验证   不能为空白,只允许使用字母字符   通过JQrelcopy插入的字段。我想过要创造   一个场景,但我无法做到正确

  6.   
<?php $form=$this->beginWidget('CActiveForm', array(  
'id'=>'symptom-form',  
'enableAjaxValidation'=>false,  
  'enableClientValidation'=>true,  

)); ?&GT;

<?php echo $form->errorSummary($model,"Please fill up the required field in red","");?>  
<div class="row">  
    <div class="floatleft"><?php echo $form->labelEx($model,'body_system_id',   array ('id'=>'label_body_system', 'class'=>'label_name')); ?>  </div>
    <div class="floatright"><?php echo $form->dropDownList($model, 'body_system_id',    CHtml::listData(SystemMaster::model()->findAll("status != 'R'"),
                                    'id', 'system_name'),array('prompt' => ' ------------- Select ------------')); ?>  </div> 
    <?php echo $form->error($model,'body_system_id'); ?>
</div>


<div class="row">
    <div class="floatleft"><?php echo $form->labelEx($model,'symptom', array ('id'=>'label_symptom', 'class'=>'label_name')); ?></div>
    <div class="floatright"><?php echo $form->textField($model,'symptom',array('rows'=>6, 'cols'=>50)); ?></div>
    <?php echo $form->error($model,'symptom'); ?>
</div>

<div class="row">
    <div class="floatleft"><?php echo $form->labelEx($model,'symptom_type', array ('id'=>'symptom_type', 'class'=>'label_name')); ?></div>
    <div class="floatright"><?php echo $form->radioButtonList($model,'symptom_type',array('T'=>'TextBox','A'=>'TextArea', 'D'=>'DropDown', 'C'=>'CheckBox'), array("id"=>"r_list")); ?></div>
    <?php echo $form->error($model,'symptom_type'); ?>
</div>

<div class="form" id="symptom_value">
        <?php 
            $this->widget('ext.jqrelcopy.JQRelcopy',array(

            //the id of the 'Copy' link in the view, see below.
            'id' => 'copylink',

            //add a icon image tag instead of the text
            //leave empty to disable removing
            'removeText' => '<img src="images/delete.png" /><small>Delete</small>',

            //htmlOptions of the remove link


 'removeHtmlOptions' => array('style'=>'color:red;float:left;position:absolute;'),

            //options of the plugin, see http://www.andresvidal.com/labs/relcopy.html
            'options' => array(

                //A class to attach to each copy
                'copyClass'=>'newcopy',

                // The number of allowed copies. Default: 0 is unlimited
                'limit'=>0,

                //Option to clear each copies text input fields or textarea
                'clearInputs'=>true,

                //A jQuery selector used to exclude an element and its children
                //'excludeSelector'=>'.skipcopy',

                //Additional HTML to attach at the end of each copy.
                        //'append'=>CHtml::tag('span',array('class'=>'hint'),'You can remove this line'),
                'append'=>CHtml::tag('span',array('class'=>'hint'),''),
            )
            ))
        ?>

    <!-- ---------------The given codes are used to display Symptom Values if already exists ---------------->

    <div class="topHeading" id="sli_title" ><span class="label_name">Symptom Values</span></div>

     <?php 
        if (count($symptom)>0 & $flag == 'update')
        {
            ?>
            <?php
            for ($i=0; $i<count($symptom); $i++)
            {
                ?>
              <div class="row copy">

                            <?php
                            echo CHtml::Textfield('symptom_value[]', $symptom[$i] ,array('class'=>'skipcopy','style'=>'float:left; width:150px; margin-right:5px;'));?>

                            <?php if ($i>0)
                            {
                                ?>
                                <a href="#" onclick="$(this).parent().remove(); return false;" style="color: red;"><img src="images/delete.png"  align="" /><small>Delete</small></a>
                                                                <span class="hint"></span>

                            <?php 
                            } 

                            ?>

             </div> <?php  
            }
            ?>   
            <?php
        }
        else
        {
        ?>            
                        <div class="row copy">
                            <?php $i=0;
                            echo CHtml::Textfield('symptom_value[]', " " ,array('class'=>'skipcopy'));?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php //echo $form->dropDownList($model, 'body_system_id', CHtml::listData(SystemMaster::model()->findAll("status != 'R'"),
                                  //'id', 'system_name'),array('prompt' => ' ------------- Select ------------')); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <?php if ($i>0)
                        {
                            ?>
                            <div class="floatright"><a href="#" onclick="$(this).parent().remove(); return false;" style="color: red;"><img src="images/delete.png"  align="" /><small>Delete</small></a>
                                                            <span class="hint"></span>
                                                            </div>
                        <?php 
                        } $i++;

                        ?>


                        </div>
            <?php
        }
         ?>
            <div class="row"><div><a id="copylink" href="#" rel=".copy"> <img src="images/add.png" align="" /><small>Add Another</small></a></div></div>

                </div>

        <!-- Symptom Values -->
            <div class="row buttons">
    <div class="floatright"><?php //echo CHtml::submitButton($model->isNewRecord ? 'Save' : 'Save', array ('onClick'=>'validate()')); ?></div>
            <div class="floatright"><?php echo CHtml::submitButton($model->isNewRecord ? 'Save' : 'Save'); ?></div>
</div>
    <div class="floatright"><?php //echo CHtml::hiddenfield('Sys_val',' ' ,array ('id'=>'Sys_val')); ?></div>

<?php $this->endWidget(); ?>
</div><!-- form -->
<script>
$(document).ready(function() {
    check();

    function check()
    {

            if ($("#Symptom_symptom_type_2").prop('checked') || ($("#Symptom_symptom_type_3").prop('checked')))
            {
                $("#symptom_value").show()
            }
            else 
            {
                $("#symptom_value").hide()
            }
    }

});
if ($("#Symptom_symptom_type_2").click(function()
{
    $("#symptom_value").show()
}));

if ($("#Symptom_symptom_type_3").click(function()
{
    $("#symptom_value").show()
}));

if ($("#Symptom_symptom_type_1").click(function()
{
    $("#symptom_value").hide()
}));

if ($("#Symptom_symptom_type_0").click(function()
{
    $("#symptom_value").hide()
}));
function validate()
   {
   var body_system = document.getElementById("Symptom_body_system_id").value
   var symptom = document.getElementById("Symptom_symptom").value


   if ($("#Symptom_symptom_type_0").attr("checked") != "checked" 
      && $("#Symptom_symptom_type_1").attr("checked") != "checked" 
      && $("#Symptom_symptom_type_2").attr("checked") != "checked" 
      && $("#Symptom_symptom_type_3").attr("checked") != "checked"
      || (body_system == "" || symptom == ""))
   {
        alert("Please enter all the mandatory fields Body System , Symptom  and Symptom Type");
   }
   return;
   }
</script>

0 个答案:

没有答案