[EXTENSION] Bootstrap

Hi Chris83,

Is there any reason why this code should not work?




Yii::app()->getClientScript()->registerScript(

	'addManufacturer',

	"function addManufacturer()

	{

		".CHtml::ajax(

			array(

				'url'=>array('manufacturer/create'),

				'data'=> 'js:$(this).serialize()',

				'type'=>'post',

				'dataType'=>'json',

				'success'=>"function(data)

				{

					if (data.status == 'failure')

					{

						$('#addManufacturer div.divLoader').fadeOut(500, function(){

							$('#addManufacturer div.divForForm').html(data.div).fadeIn(500, function(){

								// Here is the trick: on submit-> once again this function!

								$('#addManufacturer div.divForForm form').submit(addManufacturer);

							});

						});

					}

					else

					{

						$('.alert').bootAlert('alert',data.flash.key,data.flash.message);

						$('#addManufacturer div.divForForm').html(data.div);

						$('#addManufacturer').delay(2000).fadeOut(500);

						$('.modal-backdrop').delay(2000).fadeOut(500);

					}

				}",

			)

		)."

	    return false;

	}",

	CClientScript::POS_END

);



I’ve been following this tutorial http://www.yiiframework.com/wiki/145/cjuidialog-for-create-new-model/ about using ajax to create new manufacturers when I’m in my product create view.

Adding them works perfectly, but I cannot use $(’#addManufacturer’).bootModal(‘close’) or $(’.alert’).bootAlert(…).

With both of those functions it says “$(…).boot…(…)” is not a function (e.g. “$(’#addManufacturer’).bootModal(‘close’) is not a function”).

Cheers and thank you so much for your extension!

Edit: never mind, I fixed it. It was an issue with dynamically added javascript working in a different scope than your extensions, so it couldn’t find them. Changing my code to this works:




Yii::app()->getClientScript()->registerScript(

	'addManufacturer',

	"( function( $ ) {

	$('#addManufacturerLink').click(function(){

		addManufacturer();

		$('#addManufacturer').bootModal('open');

		return false;

	});

	function addManufacturer()

	{

		".CHtml::ajax(

			array(

				'url'=>array('manufacturer/create'),

				'data'=> 'js:$(this).serialize()',

				'type'=>'post',

				'dataType'=>'json',

				'success'=>"function(data)

				{

					if (data.status == 'failure')

					{

						$('#addManufacturer div.divLoader').fadeOut(500, function(){

							$('#addManufacturer div.divForForm').html(data.div).fadeIn(500, function(){

								// Here is the trick: on submit-> once again this function!

								$('#addManufacturer div.divForForm form').submit(addManufacturer);

							});

						});

					}

					else

					{

						$('.alert').bootAlert('alert',data.flash.key,data.flash.message);

						$('#addManufacturer div.divForForm').html(data.div);

						$('#addManufacturer').bootModal('close');

					}

				}",

			)

		)."

	    return false;

	}

} )( jQuery );",

	CClientScript::POS_END

);



The only thing that happens now is that I get 2 “success” messages. It seems like the function is called twice, even though (when I debug the JavaScript) it’s not doing that…

Edit: Figured out it’s not called twice, but executed twice because jQuery gets registered 2 times. Once when the page is loaded and once when the bootModal form is rendered. I know how to stop all javascript from being rendered in the modal form, but I would like to keep JS validation there. Also it seems that overriding the “run” function of cActiveForm not to include jQuery is not enough… Is there any other place that loads it when BootActiveForm is run?

Thanks avalon, that worked, still figuring this all out!

No problem, of course. I can assure you I’m still figuring it all out as well and swearing every now and then along the way :wink:

thank you for this great and useful extension. really saving my life

Awesome extension!

A couple of questions:

  1. Are you upgrading to Bootstrap 2.0?

  2. How to add dropdowns to dropdowns items in BootNav?

A third one:

In your example of BootNav, the dropdowns stays displayed when I click on the other dropdown. Is this the intended behaviour?

Thank you in advance!

Hi.

Does anybody have an example of how to use BootActiveForm and the bootfields with CForm?.

Thank you in advance!

Yes, I’m going to upgrade to Bootstrap 2.

Bootstrap top-bar does not support dropdowns for dropdown items.

And yes, right now that’s the behavior.

hi m8 i have the same problem but even though i tried your proposal it didnt work…

to be more specific here are my files :

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'=>'MusicBox+',


	

	// preloading 'log' component

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

	 // preload the bootstrap component


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.extensions.bootstrap.widgets.*',

	),


	'modules'=>array(

		// uncomment the following to enable the Gii tool

		

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'123',

		 	// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

			'generatorPaths'=>array(

			'bootstrap.gii', // since 0.9.1

			),

		),

		

	),


	// 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/aaaa.db',

		),

		// uncomment the following to use a MySQL database

		

		'db'=>array(

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

			'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',

				),

				*/

			),

		),

		

		'bootstrap'=>array(

        'class'=>'testdrive.protected.extensions.bootstrap.components.Bootstrap',

		),

	),


	// application-level parameters that can be accessed

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

	'params'=>array(

		// this is used in contact page

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

	),

);

The file that has the error is located in this folder

C:\wamp\www\yii\testdrive\protected\extensions\bootstrap\components\Bootstrap.php

(testdrive is the name of my application)

sorry for my silly question but i’ve used a lot of combination and i am still facing this stupid error

and i am sure that i’m making something really obvious wrong…

plz help!

Did you try using


'class'=>'application.extensions.bootstrap.components.Bootstrap',

instead of


'class'=>'testdrive.protected.extensions.bootstrap.components.Bootstrap',

?

lol it worked…i am new and i thought that "application" should be the application name…

i dont understand how this works…but it does :)

thanks a lot!

You can also use ext instead of application.extensions. It’s a shorthand and at least I prefer that.

Thank you!

Hi!

How to add ‘condensed’ style to BootGridView and BootDetailView?

TIA!

I am new to bootstrap, and fairly new to yii.

I want to know, how can we use properties like span columns in bootstrap plugin.

Also when i render a page, by modifying the layout (main.php) file, when i use BootNav to render the page,

the page is correctly rendered in twitter style, with a twitter like bar at the top, but the main content under it seems to go under it, (i.e. the topbar comes over my main content). Please help in this regard.

Set the ‘top’ property of your body tag to 30px or something, and set it to position: relative IIRC.

It’s written in the TB docs.

what is TB docs? do you mean Twitter Bootstrap docs?

Good guess.

Here:

http://twitter.github.com/bootstrap/components.html#navbar

[color=#333333][/color]

[color=#333333][/color]

You can specify the css class for BootGridView just like for CGridView, by giving it in the htmlOptions.

Upgrading this extension to Bootstrap 2 is now almost complete.

I will still need to do some testing but I’m quite confident that the next release will be ready by the end of this week. I will post a link to a demo shortly so that everyone can get a preview of the upcoming changes.

Hang in there! :)

As mentioned above I’m developing the new release for this extension with support for Bootstrap 2.

Here’s a working demo with some of the polished and new widgets in the upcoming release:

http://www.cniska.net/yii-bootstrap/demo/

Enjoy!