robregonm:
Sería súper útil tener la vista completa, de esa manera podremos pensar en una posible alternativa de solución.
Quedo pendiente del código completo de la vista.
Saludos
Perdón es que ayer no tenia la vista a mano…
Esta es la parte de la vista que se encarga de tomar los datos y pasarlos a Ajax via el ajaxSubmitButton.
<div class="form" id="detalle">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'detalle-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array(
'onsubmit'=>"return false;",/* Disable normal form submit */
'onkeypress'=>" if(event.keyCode == 13){ send(); } " /* Do ajax call when user presses enter key */
),
)); ?>
<tr>
<div class="row">
<?php echo CHtml::label('Ingreso de Productos','detalleLabel')?>
</div>
</tr>
<tr>
<td>
<div class="row">
<?php echo $form->labelEx($detalleFactura,'Producto_id'); ?>
<?php echo $form->textField($detalleFactura,'Producto_id',array('size'=>7)); ?>
<?php
// ext is a shortcut for application.extensions
Yii::import('zii.widgets.jui.CJuiAutoComplete');
$this->widget('ext.myAutoCompleteExtended', array(
'name' => 'producto_autocomplete',
'sourceUrl' => $this->createUrl('facturacion/autocompleteProducto'),
// attribute_value is a custom property that returns the
// name of our related object -ie return $model->related_model->name
'value' => $detalleFactura->isNewRecord ? '': $detalleFactura->producto->Producto,
'options' => array(
'minLength'=>2,
'autoFill'=>false,
'focus'=> 'js:function( event, ui ) {
$( "#producto_autocomplete" ).val( ui.item.name );
return false;
}',
'select'=>'js:function( event, ui ) {
$("#'.CHtml::activeId($detalleFactura,'Producto_id').'")
.val(ui.item.id);
$("#'.CHtml::activeId($detalleFactura,'Precio').'")
.val( ui.item.price );
return false;
}',
),
'htmlOptions'=>array('class'=>'input-1', 'autocomplete'=>'off'),
'methodChain'=>'.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.name + "</a>" )
.appendTo( ul );
};'
));
?>
<?php echo $form->error($detalleFactura,'Producto_id'); ?>
</div>
</td>
<td>
<div class="row">
<?php echo $form->labelEx($detalleFactura,'Precio'); ?>
<?php echo $form->textField($detalleFactura,'Precio',array('size'=>9,'readonly'=>true)); ?>
<?php echo $form->error($detalleFactura,'Precio'); ?>
</div>
</td>
<td>
<div class="row">
<?php echo $form->labelEx($detalleFactura,'Cantidad'); ?>
<?php echo $form->textField($detalleFactura,'Cantidad',array('size'=>9,'value'=>1)); ?>
<?php echo $form->error($detalleFactura,'Cantidad'); ?>
</div>
</td>
<td>
<div class="row">
<?php echo $form->labelEx($detalleFactura,'Descuento'); ?>
<?php echo $form->textField($detalleFactura,'Descuento',array('size'=>9,'value'=>0)); ?>
<?php echo $form->error($detalleFactura,'Descuento'); ?>
</div>
</td>
<td>
<div class="row">
<?php echo $form->labelEx($detalleFactura,'Subtotal'); ?>
<?php echo $form->textField($detalleFactura,'Subtotal',array('size'=>9,'value'=>0,'readonly'=>true)); ?>
<?php echo $form->error($detalleFactura,'Subtotal'); ?>
<?php
Yii::app()->getClientScript()->registerScript('subTotalCalculator',
'function updateSubTotal() {
$(\'#'.Chtml::activeId($detalleFactura,'Subtotal').'\')
.val(parseFloat($(\'#'.CHtml::activeId($detalleFactura,'Precio').'\').val()) *
parseFloat($(\'#'.CHtml::activeId($detalleFactura,'Cantidad').'\').val()) -
parseFloat($(\'#'.CHtml::activeId($detalleFactura,'Descuento').'\').val()));
}',
CClientScript::POS_HEAD);
Yii::app()->getClientScript()->registerScript('subTotalUpdater',
'$(\'#'.CHtml::activeId($detalleFactura, 'Precio').', #'
.Chtml::activeId($detalleFactura, 'Cantidad').', #'
.Chtml::activeId($detalleFactura, 'Descuento')
.'\').die(\'blur.calculator\').live(\'blur.calculator\', function() { updateSubTotal(); });',
CClientScript::POS_READY);
?>
</div>
</td>
<td>
<div class"row buttons">
<?php echo CHtml::ajaxSubmitButton('+',array('facturacion/ajax')); ?>
</div>
</td>
</tr>
<?php $this->endWidget(); ?>