Yii Framework Forum: Yii Cjuiautocomplete Not Saving Into Textarea - Yii Framework Forum

Jump to content

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

Yii Cjuiautocomplete Not Saving Into Textarea Rate Topic: -----

#1 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 04 January 2013 - 06:08 AM

Happy New Year all!

Sorry to be a thicko - im back to a Yii project, and I've got the auto / suggest working, e.g. I type "tea " and "Teacher" appears, but when I submit, it says the field is empty, and looking with FireBug the field value doesnt have "Teacher" in it..

Do I need a hidden field with a specific ID/Name?



    <div class="row">
		<?php echo $form->labelEx($model,'client_2_occupation'); ?> [Auto from DB]
		<?php //echo $form->textField($model,'client_2_occupation',array('class'=>'typeahead-occupation','size'=>60,'maxlength'=>128)); ?>
        <?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
		  //'model'=>$model,
		  'id'=>'client_2_occupation',
		  'name'=>'client_2_occupation',
		  'value'=>"Type keyword in here...",
		  'source' => CController::createUrl('site/suggest'),
		  'options'=>array(
		    'delay'=>300,
			'minLength'=>2,
		  ),
          )); ?>
		<?php echo $form->error($model,'client_2_occupation'); ?>
	</div>


	/**
	 * Enables suggestive form fields.
	 */
	public function actionSuggest()
    {
		if (Yii::app()->request->isAjaxRequest && isset($_GET['term'])&&($keyword=trim($_GET['term']))!=='')
		{
				$models=FormFields::model()->findAll(array(
						'condition'=>'value_int LIKE :keyword OR value_char LIKE :keyword',
						'order'=>'value_char',
						'limit'=>5,
						'params'=>array(':keyword'=>"$keyword%")
				));
				$suggest=array();
				foreach($models as $model) {
						$suggest[] = array(
								'label'=>$model->value_char,
								'value'=>$model->value_char
						);
				}
				echo CJSON::encode($suggest);
		}               
        }

0

#2 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 04 January 2013 - 07:24 AM

Ok, so I;ve tweaked it, and now it;s working so far!

    <div class="row">
		<?php echo $form->labelEx($model,'client_1_occupation'); ?> [Auto from DB]
        <?php
        $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
          'name'=>'LeadsAnnuity[client_1_occupation]',
           'source' => CController::createUrl('site/suggest'),
           'value' => ($model->client_1_occupation->client_1_occupation) ? $model->client_1_occupation->client_1_occupation : $model->client_1_occupation,
           'options' => array(
             'showAnim' => 'fold',
             'select' => 'js:function(event, ui){ jQuery("#client_1_occupation").val(ui.item["id"]); }'
            ),
            'htmlOptions' => array(
              //'style' => 'height:20px;'
            ),
        ));
        ?>
		<?php echo $form->error($model,'client_1_occupation'); ?>
	</div>

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