Multimodelform + Cjuiautocomplete

Please …

For the first record of the table works well, but for the second, the autocomplete does not work

I do not know I’m doing wrong

thank you very much

This is the code:

// _form.php

$detalleFormConfig = array(


			'elements'=>array(


			


			'referencia'=>array(


				'type'=>'text',


				'size'=>'10',


				'maxlength'=>10,


				'id'=>'referencia',


				'STYLE'=>'text-align:right; width:90px',


			),


			


			'descripcion'=>array(


				'type'=>'zii.widgets.jui.CJuiAutoComplete',


					'model'=>$detalle,


					'attribute'=>'descripcion',


					'source'=>'js: function(request, response) {


                            $.ajax({


                                url: "'.$this->createUrl('autocompletedescripcion').'",


                                dataType: "json",


                                data: {


                                    term: request.term,


									idFabricaSeleccionada: $("#Pedido_fabrica_id").val(),


									idTarifaFabricaSeleccionada: $("#tarifa_id").val()


									


                                },


                                success: function (data) {


                                        response(data);


                                }


                            })


                         }',


					'options'=>array(


						'minLength'=>2,


						'showAnim'=>'fold',


						'select'=> 'js:function(event, ui)


							{


								$("#descripcion").val(ui.item.value);


								$("#porcentajeImpuestos").val(ui.item.impuestos);


								$("#referencia").val(ui.item.referencia);


								$("#precio").val(ui.item.precio);


								return true;


							}'


						),


		    ),


					


					


			


			'precio'=>array(


				'type'=>'text',


				'size'=>'10',


				'maxlength'=>10,


				'id'=>'precio',


				'STYLE'=>'text-align:right; width:60px',


			),


			


			


			'cantidad'=>array(


				'type'=>'text',


				'size'=>'5',


				'maxlength'=>5,


				'STYLE'=>'text-align:right; width:60px',


				'id'=>'cantidad',


				


			),


			


		));


		


		





		$this->widget('ext.multimodelform.MultiModelForm',array(


			'id' => 'id_detalle', //the unique widget id


			'formConfig' => $detalleFormConfig, //the form configuration array


			'model' => $detalle, //instance of the form model


			'tableView' => true,


			'validatedItems' => $validatedDetalle,


			'data' => empty($validatedItems) ? $detalle->findAll('pedido_id=:idPedido', array(':idPedido'=>$model->id)): null,


			'showAddItemOnError' => false,


			'addItemText' => 'Nuevo Artículo',


			'removeText' => 'Eliminar', 


			'removeConfirm' => '¿ Eliminar el artículo seleccionado ?', 


			 


		));

// PedidoController.php

public function actionAutocompletedescripcion() {

    $res =array();


			 


	 if (isset($_GET['term'])) {


		$idFabricaSeleccionada=$_GET['idFabricaSeleccionada'];


		$idTarifaFabricaSeleccionada=$_GET['idTarifaFabricaSeleccionada'];


		


		$qtxt ='SELECT articulo.descripcion as value, articulo.referencia as referencia, articulo_tarifa.precio as precio FROM articulo INNER JOIN articulo_tarifa on (articulo.id=articulo_tarifa.articulo_id) WHERE articulo.descripcion LIKE :descripcion AND articulo.fabrica_id=:fabrica_id AND articulo_tarifa.tarifa_id=:tarifa_id ORDER BY articulo.descripcion ASC';


        $command =Yii::app()->db->createCommand($qtxt);


        $command->bindValue('descripcion', '%'.$_GET['term'].'%', PDO::PARAM_STR);


		$command->bindValue('fabrica_id', $idFabricaSeleccionada);


		$command->bindValue('tarifa_id', $idTarifaFabricaSeleccionada);


		$res = $command->queryAll(); 


    }


 


    echo CJSON::encode($res);


    Yii::app()->end();


}

to allow autocomplete extension in mmf

http://www.yiiframework.com/extension/multimodelform/

//MultiModelForm.php

public static function afterNewIdAutoComplete($element)


{


    $options = isset($element['options']) ? $element['options'] : array();


    if (isset($element['sourceUrl']))


        $options['source'] = CHtml::normalizeUrl($element['sourceUrl']);


    else


        $options['source'] = $element['source'];





    $jsOptions = CJavaScript::encode($options);





    return "if ( this.hasClass('ui-autocomplete-input') )


        {


            var mmfAutoCompleteParent = this.parent();


            // cloning autocomplete element (without data and events)


            var mmfAutoCompleteClone  = this.clone();





            // removing old autocomplete element


            mmfAutoCompleteParent.empty();


            // re-init autocomplete with default options


            mmfAutoCompleteClone.autocomplete({$jsOptions});





            // inserting new autocomplete


            mmfAutoCompleteParent.append(mmfAutoCompleteClone);


        }";


}

Hi,

I have a problem with Cjuiautocomplete, when I select my second option the autocomplete changes the first row.

Please, could you help me?

Thanks

Cuando selecciono mi segundo elemento me modifica la información de la primera fila.

Por fa me pudiesen ayudar.