Domanda

I am new with Yii and JQuery... I am using Yii CJuiAutoComplete widget and everything is working in well... but whats the easiest way for me to store the "selected value" by the user here ( "$("#selectedSchool").text(ui.item.value)" ) into PHP variable so I can insert that value into my DB

Whats the best easiest way to accomplish this in Yii? How do I store jquery value into PHP variable with respect to Yii??... please advise ..A quick example will help I am stuck thanks

 <?php
 $this->widget('zii.widgets.jui.CJuiAutoComplete',array(
'name'=>'school',
'sourceUrl'=>Yii::app()->createUrl('items/getPageTitles'),

 'options'=>array(
 'showAnim'=>'fold',
 'minLength'=>'2',
 'type'=>'get',
 'select'=>'js:function(event, ui) {

  //How do i store this below in Yii into PHP (so I can insert into DB)??
  $("#selectedSchool").text(ui.item.value);

 }'


),
'htmlOptions'=>array(
    'style'=>'width: 500px;',
    'placeholder' => 'Type your School'
   ),

 ));
 ?>

 <span id="selectedSchool"></span>
È stato utile?

Soluzione 2

I think you must use a hidden field for assign the value

for example

echo $form->hiddenField($model,'school', array('id'=>"school", 'class' => 'login_txtbox')); 

then assign the value to the field

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

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

 }'

Altri suggerimenti

zii.widgets.jui.CJuiAutoComplete use http://jqueryui.com/autocomplete/. Therefore, source should have pattern: [ { "label": "Choice1", "value": "value1" }, ... ]

example:

function actionGetPageTitles(){
    echo '[ { "label": "Choice1", "value": "value1" }, { "label": "Choice2", "value": "value2" } ]';
    return true;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top