CJuiAutoComplete + multimodelform:
It works fine for the first row, but the second does not show autocomplete support
What’s wrong?
this is my _form.php
<?php
/* @var $this PedidoController */
/* @var $model Pedido */
/* @var $form CActiveForm */
?>
<div class="form wide">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'pedido-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Los campos marcados con <span class="required">*</span> son obligatorios.</p>
<?php echo $form->errorSummary(array_merge(array($model),$validatedDetalle)); ?>
<div class="row">
<?php echo $form->labelEx($model,'numeroPedido'); ?>
<?php echo $form->textField($model,'numeroPedido',array('disabled' => true,'style'=>'width:80px;color:green;')); ?>
<?php echo $form->error($model,'numeroPedido'); ?>
</div>
<div class="row">
<?php
$detalleFormConfig = array(
'elements'=>array(
'descripcion'=>array(
'type'=>'zii.widgets.jui.CJuiAutoComplete',
'name'=>'descripcion',
'value'=>$detalle->descripcion,
'visible' => true,
'source'=>$this->createUrl('autocompletedescripcion'),
'options'=>array(
'showAnim'=>'fold',
),
),
'precio'=>array(
'type'=>'text',
'size'=>'10',
'maxlength'=>10,
'id'=>'precio',
'STYLE'=>'text-align:right; width:60px',
),
));
$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
'validatedItems' => $validatedDetalle,
'data' => empty($validatedItems) ? $detalle->findAll('pedido_id=:idPedido', array(':idPedido'=>$model->id)): null,
'showAddItemOnError' => false,
'tableView' => true, //sortable will not work
'fieldsetWrapper' => array('tag' => 'div', 'htmlOptions' => array('class' => 'view','style'=>'position:relative;background:#EFEFEF;')),
'removeLinkWrapper' => array('tag' => 'div', 'htmlOptions' => array('style'=>'position:absolute; top:1em; right:1em;')),
'addItemText' => 'Agregar',
'removeText' => 'Eliminar',
'removeConfirm' => '¿ Eliminar el artículo seleccionado ?',
));
?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Guardar' : 'Actualizar'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
My MultiModelForm.php …
/**
* Support for CJuiAutoComplete.
*
* @contributor Smirnov Ilya php1602agregator[at]gmail.com
* @param array $element
* @return string
*/
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);
}";
}
Thanks so much !!!