Yii Framework Forum: CJuiAutoComplete sourceUrl - Yii Framework Forum

Jump to content

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

CJuiAutoComplete sourceUrl Rate Topic: -----

#1 User is offline   easten 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 31-May 10

Posted 22 June 2010 - 12:39 AM

do somebody have any example on how to use CjuiAutoComplete with sourceUrl?
i read it from the documentation that it could get ajax response by using sourceUrl.
but still no demo though. thks :)
0

#2 User is offline   daveline 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 25-March 10

Posted 01 July 2010 - 10:09 AM

I am working on figuring this out, and I found this

http://www.yiiplaygr...ziiAutocomplete
0

#3 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 01 July 2010 - 02:23 PM

View Postdaveline, on 01 July 2010 - 10:09 AM, said:

I am working on figuring this out, and I found this

http://www.yiiplaygr...ziiAutocomplete


You can do like this
      $arr = array();
      foreach($models as $model)
      {
        $arr[] = array(
          'label'=>$model->some_attr,  // label for dropdown list
          'value'=>$model->some_attr,  // value for input field
          'id'=>$model->id,            // return value from autocomplete
        );
      }
      echo CJSON::encode($arr);

Edit: 'label' is useful for presenting more details in the dropdown list eg. 'name (pk)'.
/Tommy

This post has been edited by tri: 02 July 2010 - 06:18 AM

Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
2

#4 User is offline   Egorka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 15-September 09
  • Location:Kaluga, Russia

Posted 15 July 2010 - 09:55 AM


	<?php
	 $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
	'name'=>'adm_area',
 	'sourceUrl'=>array('ac_admarea'),
 'cssFile'=>false,
	'htmlOptions'=>array('placeholder'=>'Any'),
	'scriptUrl'=>'/protected/controllers/js',
	 ));
	 ?>

0

#5 User is offline   sergiorosales 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 19-September 10
  • Location:México

Posted 05 December 2010 - 01:14 AM

I'am trying with CJuiAutoComplete but the value is not submitted with the form.

My example:
~~~~
    $form=$this->beginWidget('CActiveForm', array(
	'id'=>'personas-buscapersona-form',
	'enableAjaxValidation'=>false,));
 
echo $form->hiddenField($model, 'idperson');

echo $form->labelEx($model,'nombre');
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
          //  'name' => 'Daytrip[nombre]',
            'name' => 'nombre',
            'sourceUrl' => array('reservatandem/SuggestPerson'),
            'value' =>  $model->nombre,
            'options' => array(
                'showAnim' => 'fold',
                //remove if you dont need to store the id, like i do...
                'select' => 'js:function(event, ui){ jQuery("#Daytrip_idperson").val(ui.item["idperson"]); }'
            ),
            'htmlOptions' => array(
                'style'=>'height: 20px; width: 300px;',
                //'style' => 'height:20px; w'
           	
            ),
        ));

echo CHtml::submitButton('Select');
                $this->endWidget();


in the controller

~~~~
public function actionSeleccionaCliente()
	{

    	$model=new Personas; //para seleccionar el cliente

           
		if(isset($_POST['Personas']))
		{
        
			$model->attributes=$_POST['Personas'];
        
        
                        $this->idperson=$model->idperson;
			if($model->validate())
                  
		       {
		    	$this->_model = $model;
                            
                                    $this->redirect(array('reserva02','id'=>$model->idperson));
                            
		    	}

                            
		}

		$iddropzone=Yii::app()->user->dropzone;
        	$idroll=Yii::app()->user->idroll;

		$dropzone = Dropzones::model()->findByPk($iddropzone);
           	
		$this->render('buscapersona',array(
			'model'=>$model,
			'namezone'=>$dropzone->namezone,

		));



	}

0

#6 User is offline   kylian 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 13-May 09

Posted 18 January 2011 - 12:04 PM

It works!

View Posttri, on 01 July 2010 - 02:23 PM, said:

You can do like this
      $arr = array();
      foreach($models as $model)
      {
        $arr[] = array(
          'label'=>$model->some_attr,  // label for dropdown list
          'value'=>$model->some_attr,  // value for input field
          'id'=>$model->id,            // return value from autocomplete
        );
      }
      echo CJSON::encode($arr);

Edit: 'label' is useful for presenting more details in the dropdown list eg. 'name (pk)'.
/Tommy

Thank you for this little but precious bit of code. :)
0

#7 User is offline   Herbert de Carvalho 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 19-January 11

Posted 08 February 2011 - 03:09 PM

Dear Friends,

I still did not manage to understand well the field source.

Does the line 12 of the script down indicate exatamente what? a path to directory? or archive?

09	$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
10	    'name'=>'test1',
11	    'value'=>'test21',
12	    'source'=>$this->createUrl('jui/autocompleteTest'),
13	    // additional javascript options for the autocomplete plugin
14	    'options'=>array(
15	            'showAnim'=>'fold',
16	    ),
17	));


congratulations
0

#8 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 08 February 2011 - 05:53 PM

View PostHerbert de Carvalho, on 08 February 2011 - 03:09 PM, said:

Dear Friends,

I still did not manage to understand well the field source.

Does the line 12 of the script down indicate exatamente what? a path to directory? or archive?

09	$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
10	    'name'=>'test1',
11	    'value'=>'test21',
12	    'source'=>$this->createUrl('jui/autocompleteTest'),
13	    // additional javascript options for the autocomplete plugin
14	    'options'=>array(
15	            'showAnim'=>'fold',
16	    ),
17	));


congratulations


In this case a URL. See the explanation here.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
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