开发者

Yii - How to call external javascript on every CActiveForm validation?

I would like to make a "pre开发者_StackOverflow社区view container" for form values in Yii. (so every time the user finishes entering data, the "preview container" below the form will display them, to let the user knows how the item actually looks like).

To achieve this, the only way is to call a Javascript function to update the "preview container" (using jQuery). The CActiveForm is:

<?php 
$form = $this->beginWidget('CActiveForm', array(
    'id'=>'item-form',
    'enableAjaxValidation'=>true,
)); 
?>

How do we modify it to call a javascript function each time the fields are validated?

(Note: whenever we switch between the input fields, the fields are validated dues to enableAjaxValidation=>true)

Thanks in advanced.


With jQuery you can define your own listener functions for the fields you want to update, which is probably going to be cleaner than trying to hook into the validation functions.You could monitor onchange or blur or whatever is most appropriate to your data.

The js can be loaded via Yii's registerScript function or, again, whatever is most appropriate for your app. A listener function would normally be loaded on DOM ready, i.e., with the POS_READY attribute for registerScript.

You can search the tutorials as well as this basic tutorial for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜