0

I would like to make a "preview 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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.