Yii Combobox Extension Not Working For Me

hello all

i wanted to use a dropdownlist that has autocomplete functionalities.

so i googled and found a very nice yii extension EJuiComboBox from here.

http://www.yiiframework.com/extension/combobox

i downloaded it and copied combobox folder into the protected/extensions directory.

and in my view file i used the following code




<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'version-form',

	'enableAjaxValidation'=>false,

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'VersionName'); ?>

		<?php echo $form->textField($model,'VersionName',array('size'=>50,'maxlength'=>50)); ?>

		<?php echo $form->error($model,'VersionName'); ?>

	</div>


<?php

$this->widget('ext.combobox.EJuiComboBox', array(

    'model' => $model,

    'attribute' => 'ModelID',

    // data to populate the select. Must be an array.

    'data' => $model->getAllModels(),

    // options passed to plugin

    // Options passed to the text input

    'options' => array(

        // JS code to execute on 'select' event, the selected item is

        // available through the 'item' variable.

        'onSelect' => 'alert("selected value : " + item.value);',

        // JS code to be executed on 'change' event, the input is available

        // through the '$(this)' variable.

        'onChange' => 'alert("changed value : " + $(this).val());',

        // If false, field value must be present in the select.

        // Defaults to true.

        'allowText' => false,

    ),

    // Options passed to the text input

    'htmlOptions' => array('size' => 10),

)); ?>










	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- form -->



but when i view the page in the browser.i just shows the textbox.i used firebug to debug the page.i took

the screen shot.here it is

3208

pic.png

please tell me what im missing here.i want dropdownlist to be same as demo.here is the link to that.

http://jqueryui.com/demos/autocomplete/combobox.html

please guys its argent.

weird I have tested your code its works fine, make sure you have getAllModels() returning an array.

getAllModels() works just fine.if u look at the snap shot that i attached i shows all the option in <select> tag.

also i used a simple array like this

‘data’ => array(‘yii’,‘is’,‘fun’,’!’),

i copied it from here

http://www.yiiframework.com/extension/combobox

still does not work

please help me

Hi,

I also pasted your code on a fresh webapp generated by Yii 1.1.11 and it worked directly with ‘data’ => array(‘yii’,‘is’,‘fun’,’!’),

Don’t you have any JS errors by any chance, and have you copied integrally the combobox folder (into your extensions folder) including its own ‘assets’ subfolder, containing 2 js files: jquery.ui.combobox.js, jquery.ui.widget.js, and jquery.ui.widget.min.js?

Also, you could try to empty your webroot/assets folder, it could work…

Good luck

thanks for the quick reply

im attaching my project hierarchy please take a look if im missing something

3210

hirarchy.png

thanks alot

It looks ok to me.

Don’t you have any JS errors by any chance?

Please try to empty your webroot/assets folder, it could work… who knows!

i have deleted all the files from webroot/assets folder as you suggested.but its still not working.

can you send me the testing application that you created.i will be very thankful.

i will run that application to check whether the problem is with my app or im missing something

i will really appreciate that please

also i dont know how to check for js errors.i know a little about firebug but not much please help

thanks

To send the webapp would be an overkill I guess.

Here’s what I did in simple steps:

[list=1]

[*]Create a new webapp using yiic command

[*]edit the protected/site/login.php file

[*]paste your code, only the autocomplete part, and using the ‘password’ attribute

[*]extract the combobox contents under protected/extensions

[/list]

Edit: here’s the edited login.php (successfully tested with 1.1.11)


<h1>Autocomplete demo</h1>


<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

        'id'=>'version-form',

        'enableAjaxValidation'=>false,

)); ?>


<p class="note">Fields with <span class="required">*</span> are required.</p>


<?php echo $form->errorSummary($model); ?>


<?php

$this->widget('ext.combobox.EJuiComboBox', array(

    'model' => $model,

    'attribute' => 'password',

    // data to populate the select. Must be an array.

    //'data' => $model->getAllModels(),

    'data' => array('yii','is','fun','!'),

    // options passed to plugin

    // Options passed to the text input

    'options' => array(

        // JS code to execute on 'select' event, the selected item is

        // available through the 'item' variable.

        'onSelect' => 'alert("selected value : " + item.value);',

        // JS code to be executed on 'change' event, the input is available

        // through the '$(this)' variable.

        'onChange' => 'alert("changed value : " + $(this).val());',

        // If false, field value must be present in the select.

        // Defaults to true.

        'allowText' => false,

    ),

    // Options passed to the text input

    'htmlOptions' => array('size' => 10),

)); ?>


<div class="row buttons">

        <?php echo CHtml::submitButton('Save'); ?>

</div>


<?php $this->endWidget(); ?>


</div><!-- form -->

sorry sir same problem but i managed to find something that could be the problem

i inspacted the page using google chrome and in the console tab i found this

Uncaught TypeError: Cannot call method ‘add’ of undefined jquery-ui.min.js:46

Uncaught TypeError: Object #<Object> has no method ‘autocomplete’ jquery.ui.combobox.js:11

please help

So it seems to be a JS problem. It can be many things: double registration of jQuery[-ui] can be a cause…

Anyway, for anyone reading and willing to help, which versions do you have for:

  • Yii

  • jQuery

  • jQuery-ui

Also, can you put you webapp online to see if someone can debug it?

MY yii version is 1.1.12 i just downloaded it last week.i have not included any jquery or jquery-ui in my project.but i explored my asset folder and they exist in here (webroot/assets/f3401271/js/jquery-ui.min.js)

i open that file and at the very top it says jQuery UI 1.8.1

but i could not find my Jquery file anywhere

As I told you, I tested with Yii 1.1.11, maybe the extension author, or someone familiar with extension authoring, can help

I’ve just downloaded v 1.1.12 and did the same test, it works perfectly

sorry to bother you again sir.One last thing

i have uploaded a test application on this location

please take a look at this login page for one last time.

i tried to use username field as a combobox for the test.but only textbox is display instead.

waiting for your reply

thanks

Hi,

There’s something going wrong in your app. You say you have Yii 1.1.12? Fine, but how come, your jQuery is 1.4.2 (it should be 1.7.2) and jQuery-ui is 1.8.1 (should be 1.8.22) ?

Please see what’s going on in your config and/or main layout.

Another thing, the standard Yii app doesn’t register jquery.yiiactiveform.js

Hi

i dont understand.i just downloaded the latest framework last week and created the application. :(

here is the main layout file (webroot/protected/views/layouts/main.php)




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<meta name="language" content="en" />


	<!-- blueprint CSS framework -->

	<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />

	<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/print.css" media="print" />

	<!--[if lt IE 8]>

	<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />

	<![endif]-->


	<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" />

	<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css" />


	<title><?php echo CHtml::encode($this->pageTitle); ?></title>

</head>


<body>


<div class="container" id="page">


	<div id="header">

		<div id="logo"><?php echo CHtml::encode(Yii::app()->name); ?></div>

	</div><!-- header -->


	<div id="mainmenu">

		<?php $this->widget('zii.widgets.CMenu',array(

			'items'=>array(

				array('label'=>'Home', 'url'=>array('/site/index')),

				array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

				array('label'=>'Contact', 'url'=>array('/site/contact')),

				array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),

				array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)

			),

		)); ?>

	</div><!-- mainmenu -->


	<?php $this->widget('zii.widgets.CBreadcrumbs', array(

		'links'=>$this->breadcrumbs,

	)); ?><!-- breadcrumbs -->


	<?php echo $content; ?>


	<div id="footer">

		Copyright &copy; <?php echo date('Y'); ?> by My Company.<br/>

		All Rights Reserved.<br/>

		<?php echo Yii::powered(); ?>

	</div><!-- footer -->


</div><!-- page -->


</body>

</html>



and here is main config file (webroot/protected/config/main.php)




<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'My Web Application',


	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.extenstions.*',

	),


	// application components

	'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		// uncomment the following to enable URLs in path-format

		/*

		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		*/

		'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),

		// uncomment the following to use a MySQL database

		/*

		'db'=>array(

			'connectionString' => 'mysql:host=localhost;dbname=testdrive',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),

		*/

		'errorHandler'=>array(

			// use 'site/error' action to display errors

            'errorAction'=>'site/error',

        ),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'webmaster@example.com',

	),

);



i have not not done anything with these file for this application

I believe you, and neither did I. Why don’t you re-download it or / and try again with a fresh webapp?

HI

First of all i would like to Thank you for your time that you spend solving my problem.

as you suggested i downloaded the framework again and created a brand new app and extension worked like a charm

Thanks once again

I have problem with my combobox… the list box not populate… only the textfield working…

my combobox working in my laptop but not in server… im using CentOS 6.3 with php-xml installed… what happen…?