Dynamically Populate Contents Of Form

Hi again,

I have a situation where the first element in a form is a dropdown where the user can select a pre defined template that contains pre-prepared values for the rest of the for, which the user can then customize to suit their requirement.

The table looks as follows:

id integer

template varchar

name varchar

type varchar

setting1 varchar

setting2 varchar

setting3 varchar

istemplate tinyint

in the form, the "template" is represented by a dropdown populate from the same table with the names of all records where istemplate=1, this is already working

when the user selects template name=default with id=1, i want the form to dynamically update all the other values with the values from the template’s record.

how would i go about doing this

Thank you

You should fetch predefined values via AJAX and manully fill form fields using their ids.

knock your self out

http://www.yiiframework.com/wiki/24/

Ok, I have made much progress in getting this working.

The dropdown calls the loadTemplate function which returns the data in JSON format.

The text fields get updated beautifully, but the checkboxes do not even though the right info gets sent via json:

JSON response:


{"client_id":"7","extension":"0002","name":"Template2","accountcode":"00101","number":"0123456789","type":"1","context":"public","host":"dynamic","disallow":"all","canreinvite":"1","secret":"mysecret","dtmfmode":"1","qualify":"0","jbmaxsize":"300","jbforce":"0","mac":"","hasvoicemail":"0","istemplate":"1","template_id":"6"}

View file:


		<?php 

		 echo $form->dropDownList($model,'template_id',CHTML::listData(Sipconf::model()->findAllByAttributes(array('istemplate'=>'1')),'client_id','name'),

		 array(

			 'ajax' => array(

			 	'type' => 'post',

			 	'dataType' => 'json',

			 	'url'=> CController::createUrl('sipconf/loadtemplate'),			 	

			 	'success'=>'function(data){

			 	$("#Sipconf_extension").val(data.extension);

				$("#'.CHTML::activeId($model,'name').'").val(data.name);

			 	$("#'.CHTML::activeId($model,'number').'").val(data.number);

				$("#'.CHTML::activeId($model,'accountcode').'").val(data.accountcode);

				$("#'.CHTML::activeId($model,'context').'").val(data.context);

				$("#'.CHTML::activeId($model,'dtmfmode').'").val(data.dtmfmode);

				$("#'.CHTML::activeId($model,'hasvoicemail').'").val(data.hasvoicemail);

				$("#'.CHTML::activeId($model,'host').'").val(data.host);

				$("#'.CHTML::activeId($model,'istemplate').'").val(data.istemplate);

				$("#'.CHTML::activeId($model,'jbforce').'").val(data.jbforce);

				$("#'.CHTML::activeId($model,'jbmaxsize').'").val(data.jbmaxsize);

				$("#'.CHTML::activeId($model,'mac').'").val(data.mac);

				$("#'.CHTML::activeId($model,'qualify').'").val(data.qualify);

				$("#'.CHTML::activeId($model,'canreinvite').'").val(data.canreinvite);

				}'

			 	 

				)

			 )

		 ); 

		 

		

		?>

any ideas on how to get the "canreinvite" checkbox to update with the right value?