在母版页(_form)中,我想保存三个字段
- 落下
- 文本框
选项列表,如果选择了选项列表中的某个选项,我需要出现一个 JQrelcopy,并且用户可以使用 JQrelcopy 添加许多值。存储在 JQrelcopy 中的值必须保存在其他表中。
现在的问题是我想进行 AJAX 验证,例如字段不能为空,通过 JQrelcopy 插入的字段只允许使用字母字符。我想创建一个场景,但我做不到
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'symptom-form',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
)); ?>
<?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'));?>
<?php //echo $form->dropDownList($model, 'body_system_id', CHtml::listData(SystemMaster::model()->findAll("status != 'R'"),
//'id', 'system_name'),array('prompt' => ' ------------- Select ------------')); ?>
<?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>