Yii Framework Forum: Tabular Input - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Tabular Input

#1 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 30 September 2012 - 07:58 AM

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
0

#2 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 01 October 2012 - 11:37 AM

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(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'=>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:- undefined variable form (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: OrderController cannot find the requested view "formItemsJS"

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 :)
0

#3 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 3,326
  • Joined: 10-October 10
  • Location:Denmark

Posted 01 October 2012 - 06:12 PM

/* Moved from General Discussion to Extensions ... ;) */
"Less noise - more signal"
0

#4 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 03 October 2012 - 03:13 AM

Nobody can help? :-[
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users