Yii Framework Forum: Cjuiautocomplete - Yii Framework Forum

Jump to content

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

Cjuiautocomplete It only works fine for the first row Rate Topic: -----

#1 User is offline   fart 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 11-July 13

Posted 24 July 2013 - 07:58 AM

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 !!!
0

#2 User is offline   Ahamed Rifaideen 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 383
  • Joined: 14-February 13
  • Location:chennai, tamilnadu

Posted 30 July 2013 - 01:19 PM

I think you have to use different names for autocomplete names...
My Blog - Yii Learner
0

#3 User is offline   cristianvaldesr 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 09-October 13

Posted 09 October 2013 - 09:09 AM

Hi!
I've been trying to make it work, but i cant.
Did you make it work?

Hola!
Yo no lo he logrado que me resulté.
Lograste que te funcionara??
0

#4 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 495
  • Joined: 08-October 12
  • Location:Austria

Posted 09 October 2013 - 09:18 AM

Hi,

Just try to give the different name and assign different id in htmloption.I hope it will solve your problems

Thanks
chandran nepolean
Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
0

#5 User is offline   cristianvaldesr 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 09-October 13

Posted 09 October 2013 - 02:18 PM

View Postchandran, on 09 October 2013 - 09:18 AM, said:

Hi,

Just try to give the different name and assign different id in htmloption.I hope it will solve your problems

Thanks
chandran nepolean


Hi!

The ids are differents. But i don't know how to give them differents names, can you give me an example.
Thanks!!
0

#6 User is offline   cristianvaldesr 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 09-October 13

Posted 09 October 2013 - 03:05 PM

OK, now it work. But only for the last element. Apperently, that's how it's done, working only for the last element.
Another little problem, it also removes the label from the field with the autocomplete.


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(); //THIS IS WHERE REMOVES THE AUTOCOMPLETE FROM THE PREVIUOS
// re-init autocomplete with default options
mmfAutoCompleteClone.autocomplete({$jsOptions});

// inserting new autocomplete
idTemp = mmfAutoCompleteClone.attr('id');
mmfAutoCompleteClone.attr('name', idTemp);
mmfAutoCompleteParent.append(mmfAutoCompleteClone);
}";
}
0

#7 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 495
  • Joined: 08-October 12
  • Location:Austria

Posted 10 October 2013 - 03:51 AM

View Postcristianvaldesr, on 09 October 2013 - 02:18 PM, said:

Hi!

The ids are differents. But i don't know how to give them differents names, can you give me an example.
Thanks!!


Hi,

just use rand() php method with name attribute, it will make different names :)

Thanks
chandran nepolean
Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
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