Dynamic tabular input


I want use Tabular Input for quick models creating in administration page. But I need that the count of model’s forms changed dynamically (by means of JQuery/JavaScript).

User open form for creating model and can press JavaScript-powered button "add item" to add one more model form.

Is any ready decision for it? May bee any extension?


Take a look at the extension multimodelform.

It works with simple input elements (textfield, dropdown, checkboxlists, datepicker), but not with more complex jquery based components (select2, autocomplete…).

Thanks for replies!

But I decide use custom JQuery code to solve this problem such as this code.

<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>

<script type="text/javascript">


	    var template = $('#all_answers .answer_form').clone();

	    var answersCount = 1;

	    window.addAnswer = function(){


	        var answer = template.clone().find(':input').each(function(){

	            var newId = this.id.substring(0, this.id.length-1) + answersCount;

	            this.name = this.name.replace(/\[0\]/g,'['+(answersCount-1)+']');

	            newId     = this.id.replace(/_0_/g,'_'+(answersCount-1)+'_');

	            $(this).prev().attr('for', newId);

	            this.id   = newId;


	        .attr('id', 'answer_form_' + (answersCount-1))


	        .find('h3').text("Header №"+answersCount);








<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>

	<div id="all_answers">

	<?php foreach($answers as $i=>$answer): ?>


	<div class="answer_form">

		<h3>Header №<?php echo ($i+1); ?></h3>


		<?php echo $form->errorSummary($answer); ?>



		<div class="row">

			<?php echo $form->labelEx($answer,"[$i]number"); ?>

			<?php echo $form->textField($answer,"[$i]number",array('size'=>4)); ?>

			<?php echo $form->error($answer,"[$i]number"); ?>



		<div class="row">

			<?php echo $form->labelEx($answer,"[$i]content"); ?>

			<?php echo $form->textArea($answer,"[$i]content",array('rows'=>6, 'cols'=>50)); ?>

			<?php echo $form->error($answer,"[$i]content"); ?>



		<div class="row">

			<?php echo $form->labelEx($answer,"[$i]points"); ?>

			<?php echo $form->textField($answer,"[$i]points"); ?>

			<?php echo $form->error($answer,"[$i]points"); ?>





	<?php endforeach; ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Go!'); ?>


<?php $this->endWidget(); ?>

</div><!-- form -->