[EXTENSION] multimodelform/jqrelcopy

No problem, thanks joblo, I will try something. Thanks for nice extension and your time for supporting the extension.

Can you suggest any alternative extension that i can use to support my scenario??

Hmm… sorry I have never tested or used multimodelform with ajax.

You have to debug the js-code or take a look at the console output.

Maybe you have to work with the js-afterClone codes … etc.

Samdark published another solution (without clientside cloning lik multimodelform) in his book ‘Yii 1.1 Application Development Cookbook’ (Chapter 3 Handling variable number of inputs). But this uses ajax to add records in the db and adding the form element. I’m not sure if your ‘ajax in ajax’ work with this implementation.

@ JOblo,

Good news, with some digging inside your Js file and a bit of hard coding of some type, I was able to achieve the dependent scenarios and hell, any thing even if it is a dependent dropdown type scenario or db calls or client side javascript etc.

I am not sure if this can be implemented inside your main extension. let me know if you have time and can have a look at my code. If integrating this to main extension is possible, it will be great for lots of users.


Can you publish the modified js-file with a description, what problems it solves?

An easy step what I can do, is to add a public property ‘jsFile’ to allow to use customized js-files in the next release.

So every one can copy the default file, make the changes he needs and switch to the customized js-file without touching the basic core.

Is there an option to require the user to input at least 1 record?

In your controller you have to split validate and save of the MultiModelForm as mentioned in the online docu.

//validate formdata and populate $validatedItems/$deleteItems

if (MultiModelForm::validate($model,$validatedItems,$deleteItems,$masterValues)) 





    //submit a message to the form (userflash ....)





Yes please, publish the code as it sounds like the solution I need as well. Thank you very much.


I’me a newbie and may be there is nothing new, but i’ve got an extended form element list for this multimodelform from Yii Booster components.

I’m just change inheritance in MultiModelForm.php from native yii CForm & CActiveForm classes to YiiBooster TbForm & TbActiveForm.

Additionally, you have to import needed class before this extending. Like this:


class MultiModelRenderForm extends TbForm

So i can call as form element type anything from this list:

public static $tbActiveFormMethods = array(

		'text' => 'textFieldRow',

		'password' => 'passwordFieldRow',

		'textarea' => 'textAreaRow',

		'file' => 'fileFieldRow',

		'radio' => 'radioButtonRow',

		'checkbox' => 'checkBoxRow',

		'listbox' => 'dropDownListRow',

		'dropdownlist' => 'dropDownListRow',

		'checkboxlist' => 'checkBoxListRow',

		'radiolist' => 'radioButtonListRow',

		//HTML5 types not supported in YiiBooster yet: render as textField

		'url' => 'textFieldRow',

		'email' => 'textFieldRow',

		'number' => 'textFieldRow',

		//'range'=>'activeRangeField', not supported yet

		'date' => 'datepickerRow',

		//new YiiBooster types

		'captcha' => 'captchaRow',

		'daterange' => 'dateRangeRow',

		'redactor' => 'redactorRow',

		'markdowneditor' => 'markdownEditorRow',

		'uneditable' => 'uneditableRow',

		'radiolistinline' => 'radioButtonListInlineRow',

		'checkboxlistinline' => 'checkBoxListInlineRow',

		'select2' => 'select2Row'


Now I’m trying to get this wysiwyg editors work well.

Thanks for the information but I’m still not clear; are you saying that if I change these lines in MultiModelForm.php:


class MultiModelRenderForm extends CForm



class MultiModelEmbeddedForm extends CActiveForm



to these:


class MultiModelRenderForm extends bootstrap.widgets.TbForm



class MultiModelEmbeddedForm extends bootstrap.widgets.TbActiveForm



that I’ll be able to use Ajax calls on my dropDownListRow? Please clarify, thanks!

No, i’m not assume this. Inheritance from the extended classes provide you to render some additional elements but there are still many issues with getting all of js working properly after relCopy. My first post is hasty.

In my project i want to render any wysiwyg editor instead of this textareas but after coping this editors work buggy - any buttons from the second instance affect the first instance. I think it because of brutish copying. May be, i have to change some id’s and recall some init js everytime you create a copy. Perhaps, this is a deadlock.

About you question: dont know, i will need some ajax but later.

Ok, thanks for the help!

Hi there. I want to ask if anyone know how to set default value for generated textfields.

Example: I want to get 1 textfield with money f.e. 3000$. If I click ‘add item’ and i get +1 field I need to get it value as 3000$/1. Next ‘add item’ and default value for all textfields is 3000$/2, next 3000$/3 etc…

How should I do this? It’s all new to me so any help would be appreciated. Thx ;)

I’m no JavaScript expert so after a lot of hair pulling (and kudos to @Arely and @Paul_Kish) I was finally able to get Ajax working for my dropdowns. In my invoice form line items (inventory_id, qty, price) the price gets loaded through Ajax and if it’s tagged as a fixed price then the price text input is disabled. The remaining problem is that after cloning a line item if its predecessor price was disabled then the clone inherits the disabled attribute.

I’ve tried resetting it with the jsAfterNewId option:

'jsAfterNewId' => "

	if(this.attr('id').indexOf('TSvctixln_price') >= 0)


		this.attr('disabled', 'false');



but it’s always disabled. I also tried resetting it in the change script:





		var itmprice = $(this).parents('td').next().find('.lprice');




			if(data.fixedp == '1') {itmprice.attr('disabled', 'true');} else {itmprice.attr('disabled', 'false');}








but that doesn’t reset it either. Any ideas?

Thanks for your help,

Never mind, I found a syntax error and solved the problem :rolleyes:

Hi, I’ve been using extension

jqrelcopy, with duplicate TimePicker in my form. But to clone the 2nd, MyTimePicker don’t work.

Always working in the TimePicker 1.

<div class="row copy">

    <div class="span2">

        <?php echo $form->timepickerRow(


                'class' => 'input-small','empty','options'=>array('showMeridian'=>false)


        ); ?>

        <?php // echo $form->hiddenField($model,'shift_kerja[]'); ?>


        <div class="span2">

                <?php echo $form->timepickerRow(


                'class' => 'input-small','options'=>array('showMeridian'=>false)


        ); ?>



The jqrelcopy is a bit out of date and is not tested with timepicker or other jquery based components.

The problem is always the same: you have to execute extra js-code after cloning the input to bind the cloned elements with the new id to the js-functions.

Did you try the newer extension recopy instead?

Or maybe you can try the multimodelform extension instead. This comes with support for the datetimepicker, but read the chapter Usage widget form elements from the documentation first.

Thanks Joblo… :)

Hi Joblo,About multimodelform.

How do I add a hidden input increment if every click turn on? And How do I give a limit for dynamic row???


hidden input:

Assign a hidden input in the formbuilder/formConfig and use the jsAfterNewId (or the jsAfterCloneCallback) property to increment the value.


Set the properties ‘limit’ and ‘limitText’ of the MultiModelForm widget

Read the documentation or take a look at the source.