Tabular Input

Hi,

Can anyone who has used the extension ztabularinputmanager(JS version) of Zaccaria please help me? I am having problems trying to implement it?

Thanks beforehand

Hi,

I need to input data for 2 models in my form and am using the extension ztabularinputmanager (the one which uses JS to add or remove items) I am having error messages right at the start. I used the 1st version and it run fine. But I can’t get this one to work. Here is my code for the main view:




<div class="form">




<?php Yii::app()->getClientScript()->registerScript('enab','$("#rs").change(function()

	{ if ($("#rs:checked").val()==1)

			{ $("#cli").attr("disabled",true); $("#res").attr("disabled",false); }

	  else

	  		{	$("#cli").attr("disabled",false); $("#res").attr("disabled",true); }

	}

	);');

?>




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


	'id'=>'order-form',


	'enableAjaxValidation'=>false,


)); ?>




	<p class="note">Fields with <span class="required">*</span> are required.</p>





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




	<div class="row">

	<table>

	<tr>

		<td width="18%">


		<?php echo $form->labelEx($model,'table'); ?>

		<?php echo $form->textField($model,'table',array('size'=>3,'maxlength'=>3)); ?>

		<?php echo $form->error($model,'table'); ?>

		</td>

		

		<td>

		<?php echo $form->labelEx($model,'resident'); ?>	


		<?php echo $form->checkBox($model,'resident',array('checked'=>'checked','id'=>'rs')); ?>

		<?php echo $form->error($model,'resident'); ?><br>

		<?php echo $form->labelEx($model,'reservation_id'); ?>

		<?php //echo $form->textField($model,'reservation_id',array('id'=>'res')); ?>

		<?php //echo $form->dropDownList($model, 'reservation_id',

		//CHtml::listData(Reservation::model()->findAll(), 'id','ClientId'), array('class'=>'room','id'=>'res')); ?>

		<?php echo $form->dropDownList($model, 'reservation_id',

		CHtml::listData($data, 'id','ClientId'), array('class'=>'room','id'=>'res')); ?>		

		<?php echo $form->error($model,'reservation_id'); ?>

		</td>

		<td>

		<?php echo $form->labelEx($model,'cli_name'); ?>

		<?php echo $form->textField($model,'cli_name',array('class'=>'small','disabled'=>'disabled','id'=>'cli','size'=>30,'maxlength'=>30)); ?>

		<?php echo $form->error($model,'cli_name'); ?>

		</td>		

	</tr>

	</table>

	</div>

	




<h2>Items ordered:</h2>

<table>

<thead>

<tr>

    <td width="90"><?php echo $form->labelEx(Itemtype::model(),'id')?></td>

    <td width="115"><?php echo $form->labelEx(Itemsordered::model(),'item_id')?></td>

    <td width="300"><?php echo $form->labelEx(Itemsordered::model(),'descrip')?></td>   

    <td width="45"><?php echo $form->labelEx(Itemsordered::model(),'qty')?></td>

    <td width="115"><?php echo $form->labelEx(Itemsordered::model(),'totalprice')?></td>    

    <td><?php //echo CHtml::link('add', '#', array('submit'=>'', 'params'=>array('Itemsordered[command]'=>'add', 'noValidate'=>true)));?>

		  <?php echo CHtml::link('add', '', array('onClick'=>'addRow($(this))', 'class'=>'add'));?>

    </td>

</tr>

</thead>

<tbody>

<?php foreach($itemsManager->items as $id=>$items):?>

 

<?php $this->renderPartial('_formItems', array('id'=>$id, 'model'=>$items,'itemsManager'=>$itemsManager, 'form'=>$form));?>

 

<?php endforeach;?>

</tbody>

</table>	


	<div class="row buttons">


		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>





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




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

Here is the view for _formItems:-




<script type="text/javascript">

// initializiation of counters for new elements

var lastRow=<?php echo $itemsManager->lastNew?>;

 

// the subviews rendered with placeholders

 var trRow=new String(<?php echo CJSON::encode($this->renderPartial('formItemsJS', array('id'=>'idRep', 'model'=>new Itemsordered, 'form'=>$form), true));?>);


function addRow(button)

{

    lastRow++;

    button.parents('table').children('tbody').append(trRow.replace(/idRep/g,'n'+lastRow));

}

 

 

function deleteRow(button)

{

    button.parents('tr').detach();

}

 

function set(x) {

alert(x);

var item_id ="Itemsordered_"+x+"_item_id";

var qty ="Itemsordered_"+x+"_qty";

var totalprice ="Itemsordered_"+x+"_totalprice";

var descrip ="Itemsordered_"+x+"_descrip";

$("#"+qty).val(3);

$("#"+totalprice).val(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />;




				$.get("index.php?r=order/Maj", {param: $("#"+item_id).val()}, function(data) 

				{

					alert("ok");

					$("#"+descrip).val(data.desc);

				},"json");

}  

 

 

</script>


<tr>

    <td>

        <?php echo $form->dropDownList($model,"[$id]itemtype",CHtml::listData(Itemtype::model()->findAll(), 'id', 'description')); ?> 

    </td>


    <td>

        <?php echo $form->textField($model,"[$id]item_id",array('size'=>15,'maxlength'=>15,'onchange'=>"set('$id')")); ?> 

        <?php echo $form->error($model,"item_id");?>

    </td>

    

    <td>

    <?php echo $form->textField($model,"[$id]descrip",array('class'=>'small','readonly'=>'readonly','size'=>50,'maxlength'=>50)); ?>

    <?php echo $form->error($model,"descrip");?>        

    </td>

 

    <td>

        <?php echo $form->textField($model,"[$id]qty",array('size'=>2)); ?>

        <?php echo $form->error($model,"qty"); ?>

    </td>

    

    <td>

        <?php echo $form->textField($model,"[$id]totalprice",array('size'=><img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />); ?>

        <?php echo $form->error($model,"totalprice"); ?>

    </td>    

 

    <td><?php echo CHtml::link(

        'delete', 

        '', 

        array(

            'class'=>'delete',

            'onClick'=>'deleteRow($(this))'

            ));?> 

    </td>

</tr>

If I put the javascript in the main view, I get the following error on running it:- [font="Arial Black"]undefined variable form[/font] (which is normal since $form is not yet created when the script is run)

It is in connection with this line (found in the javascript code)


var trRow=new String(<?php echo CJSON::encode($this->renderPartial('formItemsJS', array('id'=>'idRep', 'model'=>new Itemsordered, 'form'=>$form), true));?>);

If I put it in the 2nd view, I have had to include ‘itemsManager’=>$itemsManager as parameter in the renderpartial of the main view. But then I get this error: [font=“Arial Black”]OrderController cannot find the requested view “formItemsJS” [/font]

I am doing something wrong but I have no idea what it is.

@Zaccaria: in your explanation about this extension, you have a 2nd renderpartial in your main view:




<?php $this->renderPartial('form/studentJs', array('students'=>$students, 'form'=>$form));?> 

Can you please explain to me what this 2nd renderPartial do and what must this view contain? Sorry for being dumb :)

[color="#006400"]/* Moved from General Discussion to Extensions … ;) */[/color]

Nobody can help? :-[