Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

A Couple Questions About Dynamic Content And Ajax

$
0
0
I want to show some dynamic content to the user, so use a dropdown like so:

<?php 
$form->dropdownListRow($model, 'type', array_merge(array(''=>'---'),ProfileFieldRule::itemAlias('type')) ,
                array('class' => 'span5', 'maxlength' => 45, 
                    'ajax'=>array(
                        'type'=>'POST',
                        'url'=>CController::createUrl('ProfileFieldRule/showAttributes'),
                        'update'=>'#showAttributes',                        
                        ))));
?>


the action showAttributes renders some form elements, stuff like:

echo CHtml::activeDropDownList($attr, $name, array('true', 'false'));


Question 1 At this point, I'd like to know if there's a way I can access the $form variable that was created in the view? It's easier, than CHtml and if I make changes they'd persist I wouldn't have to come update them again here. If not, that's ok, I can work with CHtml.

**So far so good, until the form is submitted with errors. At that point, the generated content disappears until you change the dropdown again.**

Question 2 What's the best way to make it persist? At present I check if it's set and copy the code from showAttributes. This seems pretty redundant.

Question 3 How would I go about adding ajax validation to this form? The non dynamic portion is simple, but I don't know how to add the dynamic attributes to what's being validated.


Thanks in advance for any help, hopefully I've made it more clear with this edit!

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>