[EXTENSION] multimodelform/jqrelcopy

How to call value for each row in multimodelform?

it doesn’t work: $model->id




Hi Joblo,

Why is it that I get two columns of "Remove" for each new element?

I went back to looking after multimodelform and my problem is finally this one:

Every time I create a group element with one or more members, one additional member is saved (all fields are blank) …

I can not find what it is. This ghost member is added at the time of validation of Members:

MultiModelForm :: validate ($ member, $ validatedMembers, $ deleteMembers);

I’m lost … :(

The “ghost” member is apparently due to the copyTemplate. Now I’m searching why it’s saved as a member.

Maybe an input element of the copyTemplate is not really empty (a dropdown default value …)

Arg… it was this (dropdown)!

Thank you Joblo

Well, a diferent problem…mostly i think is JS related…

jqrelcopy worked fine, but some fields that have masked input are behaving just weird…

have 2 fields, data_emissao and data_validade, both have masks (99/99/9999).

when i execute jqrelcopy (when copy the fields)

all ok, id changed everything fine… so i have data_emissao_0, data_validade_0 and data_emissao_1 and data_validade_1.

When i type in data_validade_1 changes the text inside both data_validade.

I don’t know if i’m making myself clear (my english is not so good, as may you have noticed).

Any ideas?

This is happening for me also.

hideCopyTemplate should be set to false


			'id' => 'id_member', //the unique widget id

			'formConfig' => $memberFormConfig, //the form configuration array

			'model' => $member, //instance of the form model

			//if submitted (not empty) from the controller,

			//the form will be rendered with validation errors

			'validatedItems' => $validatedMembers,


			'hideCopyTemplate' => false, //should be set to false

I appreciate the help. This helped me to remove the duplication, but it is only a minor fix as I now do not have the ability to hide the original item. Any way around that?


I took some time to understand the code and managed to find some workarounds to achieve some little things. I guess there must be better ways to do it.

To achieve what you want, try to modify the jquery.relcopy.yii.3.3.js(or whichever version you are using) in the following way:-

Replace this:


                var parent = $(master).parent();

                var clone = $(master).clone(true).addClass(settings.copyClass+counter).append(settings.append);


by this:


                var parent = $(master).parent();

                var clone = $(master).clone(true).addClass(settings.copyClass+counter);//see the change here


Hope it works :)

But if you do not hide the template, you will no longer have the remove link.

Hi there to those who are interested with the autocomplete feature with this extension.

I worked around the extension code in all possible ways but could not get it to function. Finally I gave up and looked for a way to do it in my view form itself. The results are quite satisfactory except that the autocomplete feature never works on the 1st clone. I could not figure out why and had to give up here also.

Here is the javascript code that I added to my view:

<script TYPE="text/javascript" LANGUAGE="JavaScript"> 

function init(x) {

		var descrip = x.replace("item_id","descrip");

		var unitprice = x.replace("item_id","unitprice");	

		var obj = <?php echo $auto; ?>;


		select: function( event, ui ) {$("#"+descrip).val(ui.item.label);





And here is the code where the javascript gets fired (onfocus):

	$itemsorderedFormConfig = array(















Hope it may be of some help to someone :D

@Joblo, thank you very much for this extension. It is invaluable!!

Thank you. I will try it out.

Hi Joblo,

Thank for great extension.

It work, but I have a problem.

I need to use CUploadedFile with sub form.

I don’t know how it get data for getInstance.

Can you write example for me?

Thank a lot.

Best wish.

Hi all

I need a help with a simple question, how to call value for each row in multimodelform? I need to link the dropdonwlist ‘subactivitat_id’ to the value selected in the dropdownlist ‘activitat_id’. Attached the code below.

$memberFormConfig = array(




			'items'=>array(''=>'') + CHtml::listData(Activitats::model()->findAll(array('order'=>'descripcio ASC')), 'id_activitat', 'descripcio'),


                        var id = this.id;

						var indexid = id.substring(24,id.length);

						var drop = "#Imputacions_subactivitat_id"+indexid;

						var url ="'.$this->createUrl("Setmanes/dynamicSubActivitat").'";

						$.post(url, { id: $(this).val() }, function(data) {

							data = JSON.parse(data);






			'items'=>array(''=>'') + CHtml::listData(Subactivitats::model()->findAll(array('order'=>'descripcio ASC', 'condition'=>'activitat_id=:activitat_id', 'params'=>array(':activitat_id'=>(int) $validatedMembers['1']->activitat_id))), 'id_subactivitat', 'descripcio'),


Thks for your help.


to Sgonzalesmo an example of dependant dropdown in multimodelform. In my use, there is only one occurence, so you’ll have to modify some more.

The "name" of the field is different if your occurrence is created or updated, so i use a variable ($update) in my form

$update = '#'.CHtml::activeId($relStudentSemester,'level');

foreach ($relStudentSemester_w as $models)



   $update = "#RelStudentSemester_u___0_level";



$relStudentSemesterFormConfig = array(












		'success'=>'function(data) {






In the controller, actionTestResult:




		$dropDownA = CHtml::tag('option', array('value'=>$level),CHtml::encode($level),true);




		$dropDownA = CHtml::tag('option', array('value'=>''),CHtml::encode('-'),true);

		$dropDownA .= CHtml::tag('option', array('value'=>'A1'),CHtml::encode('A1'),true);

		$dropDownA .= CHtml::tag('option', array('value'=>'A2'),CHtml::encode('A2'),true);

		$dropDownA .= CHtml::tag('option', array('value'=>'B1'),CHtml::encode('B1'),true);

		$dropDownA .= CHtml::tag('option', array('value'=>'B2C'),CHtml::encode('B2C'),true);


	echo CJSON::encode(array(



Hope it will help.

I’ve set up this example on my localhost.

However, I get an error that WebBaseController.php is missing. Anyone that has successfully setup this example? What does the missing component do? Any chance you could upload it?



I managed to fix the two remove columns issue, by changing multimodelform php code instead of changing relcopy code:

In function getClientOptions() on line 749 I changed

if (!empty($this->removeText))


 if (!empty($this->removeText) && !$this->hideCopyTemplate)

If the developer is reading this he might put it in the next version if it does not make problems elsewhere…


Many thanks - fixed and published in v. 4.0

I am having problems with CJuiDatePicker. Unless the date attribute is required in my model than the date column does not appear in the view. However, I would like the date attribute to NOT be required. Does anyone have any suggestions? Thanks in advance.

Please see my _form.

	<div class="hidden">

		<?php $form->widget('zii.widgets.jui.CJuiDatePicker', array(





		               'showAnim'=>'fold')),true); ?>

		<?php echo $form->error($lease,'lxp'); ?>



	$leaseFormConfig = array(
















	      'id'=>'id_lease', //the unique widget id

	      'formConfig'=>$leaseFormConfig, //the form configuration array

	      'model'=>$lease, //instance of the form model

	      //if submitted not empty from the controller,

	      //the form will be rendered with validation errors



	      'addItemText'=>'<br><button type="button" class="btn-info">Add Tenant</button><br><br>',


	      'removeText'=>'<button type="button" class="btn-danger">Remove</button>',	      


	      //array of lease instances loaded from db



	      //display as a horizontal table



	      //prevent extra remove from tableView