Yii CActiveForm 日期验证 [英] Yii CActiveForm date validation

查看:27
本文介绍了Yii CActiveForm 日期验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本日期"字段的日期验证不起作用.

http://sky-walker.net/temp/test/yii/testdate/index.php?r=site/login

如果我将其设置为需要,则必需"验证有效.

我希望文本字段在提交表单以及使用ajax失去焦点时变为红色或绿色.如果它变成红色,还会出现一条错误消息.

来自 login.php

<?php echo $form->labelEx($model,'textDate');?><?php echo $form->textField($model,'textDate');?><?php echo $form->error($model,'textDate');?>

来自 LoginForm.php

public $textDate;

来自规则()

...array('textDate', 'date', 'format'=>'d/M/yyyy'),...

解决方案

在您的表单上,您没有 ajax 验证.您拥有的验证是 javascript 验证.如果您查看 Firebug,那么您将看到没有与服务器通信 => 您只有 js 验证,您没有验证模型.

你必须设置一些变量才能让它通过ajax运行

'enableAjaxValidation' =>真的,'clientOptions' =>大批('validateOnSubmit' =>真的,'validateOnChange' =>真的,),

The date validation for the "Text Date" field isn't working.

http://sky-walker.net/temp/test/yii/testdate/index.php?r=site/login

The "required" validation works if I set it as required though.

What I want the text field to do is to either turn red or green when the form is submitted and also when the focus is lost using ajax. If it turns red an error message should also appear.

From login.php

<div class="row">
    <?php echo $form->labelEx($model,'textDate'); ?>
    <?php echo $form->textField($model,'textDate'); ?>
    <?php echo $form->error($model,'textDate'); ?>
</div>

From LoginForm.php

public $textDate;

From rules()

...array('textDate', 'date', 'format'=>'d/M/yyyy'),...

解决方案

On your form you do not have ajax validation. The validation you have is javascript validation. If you take a look with Firebug then you will see nothing is communicated with the server => you only have js validation, you do not validate the model.

YOu have to set up some variables to make it run through ajax

'enableAjaxValidation' => true,
'clientOptions' => array(
        'validateOnSubmit' => true,
        'validateOnChange' => true,
),

这篇关于Yii CActiveForm 日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆