[EXTENSION] Bootstrap

Scenario: Boot/TbNavbar => Boot/TbMenu => li => form.

Try this… (inside the items array of Boot/TbNavbar):


array(

  'class'=>'bootstrap.widgets.TbMenu',

  'htmlOptions'=>array('class'=>'pull-right'),

  'encodeLabel'=>false,

  'items'=>array(				

    array('label'=>'Login', 'url'=>'#', 'items'=>array(


      array('label'=>'<form>

          <input type="text" placeholder="user id" id="userid"/>

          <input type="password" placeholder="password" name="userpassword"/>

        </form>', 

        'url'=>null, 'visible' => Yii::app()->user->isGuest)),


    ),

  ),

),

important:

  • ‘encodeLabel’=>false … so the form is not encoded but rendered properly.

  • ‘url’=>null … of course you need to add a submit button.

  • browser test … check how it looks like in different browser and OS; please provide feedback for us!

Tested in FF/Safari on Mac OS.

Hope this helps!

-DF

There’s nothing missing in the error message, it tells you exactly what’s not defined (hence missing in the model class): the attribute name. Make sure you’re using an attribute name that is set under rules() in /protected/models/LoginForm.php. Usually you will have something like…


array('username, password', 'required'),

//or

array('email, password', 'required'),

All attributes that require user input need to be added in rules() of the model class.

Cheers,

-DF

Thanks…

Don Felipe

i have just define on rule model

but i still have this error message

and I try to define whit tis code





$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(

    'id'=>'verticalForm',

	'enableClientValidation'=>true,

    'htmlOptions'=>array('class'=>'well'),

)); ?>



But there is’nt any changes on that error message,

what this error message means?

Thx

@Müller That’s an interesting idea, however I probably wouldn’t add a fixedItems property but instead allow developers to configure a fixed property per item. What do you think about this solutions? Here’s a quick example:




$this->widget('bootstrap.widgets.TbNavbar', array(

	.....

	'items'=>array(

		array(

			'class'=>'bootstrap.widgets.TbMenu',

			.....

			'fixed'=>true, // like so

			'items'=>array(

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

				.....

			),

		),

		.....

	),

));



Client-side validation works fine on my side… the newest alpha and latest 0.x version. Besides, there’s no difference on how enableClientValidation is handled in BootActiveForm vs TbActiveForm. Just in case, what Yii and alpha-bootstrap versions do you use?

@yiistudent I’d suggest that you don’t use an alpha version but instead the stable 0.x version.

Hi @Chris83

This was my first idea, the reasons (that I can remember now) why I didn’t implement like that was:

  • I didn’t want to change that much of your code to separate the $items (checking the item fixed property) in 2 arrays before rendering them, one before the TbCollapse and one inside it.

  • It could be confuse when you write a code like this:




$this->widget('bootstrap.widgets.TbNavbar', array(

	.....

	'items'=>array(

		array(

			'class'=>'bootstrap.widgets.TbMenu',

			.....

			'fixed'=>false,

			'items'=>array(

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

				.....

			),

		),

		.....

		array(

			'class'=>'bootstrap.widgets.TbMenu',

			.....

			'fixed'=>true, // This will show on right side of the navbar as by the current idea

			'items'=>array(

				array('icon'=>'magnifier', 'label'=>'Search', 'url'=>array('/site/search'),

				.....

			),

		),

		.....

		array(

			'class'=>'bootstrap.widgets.TbMenu',

			.....

			'fixed'=>false,

			'items'=>array(

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

				.....

			),

		),

	),

));



Where the middle TbMenu will be displayed last.

But if can come with a neat implementation of the property fixed, I do think it’s better.

Sure only got the code for the screenshot 1 since the #2 code I only changed to it briefly to illustrate my point.

Here is the view bit for #1: (fairly straightforward code really)




<?php $form = $this->beginWidget('bootstrap.widgets.BootActiveForm', array(

    'id' => 'job-form',

    'enableAjaxValidation' => false,

)); ?>


<p class="help-block">Fields with <span class="required">*</span> are required.</p>


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


<div class="hidden">

    <?php echo $form->uneditableRow($model, 'return_authorisation_id', array('class' => 'span5')); ?>

</div>


<?php echo $form->dropDownListRow(

    $model,

    'job_status_id',

    CHtml::listData(JobStatus::model()->findAll(), 'id', 'title'),

    array(

        'class' => 'span5',

    ));

?>


<?php echo $form->textFieldRow($model, 'product_received_time', array('class' => 'span5 datepicker')); ?>


<?php echo $form->textFieldRow($model, 'hours_worked', array('class' => 'span2', 'append' => 'hours')); ?>


<?php echo $form->textAreaRow($model, 'note', array('rows' => 6, 'class' => 'span5')); ?>


<?php echo $this->renderPartial('_parts_used', array('model' => $model)); ?>


<input type="hidden" name="jumper" id="jumper">


<div class="form-actions">

    <?php $this->widget('bootstrap.widgets.BootButton', array(

    'buttonType' => 'submit',

    'type' => 'primary',

    'icon' => 'ok white',

    'label' => $model->isNewRecord ? 'Create' : 'Save',

)); ?>


    <?php $this->widget('bootstrap.widgets.BootButton', array(

    'buttonType' => 'button',

    'type' => 'info',

    'icon' => 'print white',

    'label' => 'Save and Print',

    'htmlOptions' => array(

        'class' => 'save-print'

    ),

)); ?>

</div>


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



Thx All

I got the same, use alpha or current Yii-bootstrap extention and also the same error for prevoius version.

this my yii config script





return array(

	'basePath'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=&gt;'Stater',

	'defaultController' =&gt; 'site/login',

	// preloading 'log' component

	'preload'=&gt;array(

		'log',

		'bootstrap',

		),


	// autoloading model and component classes

	'import'=&gt;array(

		'application.models.*',

		'application.components.*',

		'ext.bootstrap.widgets.*',

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

		'application.modules.rights.*',

		'application.modules.rights.components.*',

	),


	'modules'=&gt;array(

		// uncomment the following to enable the Gii tool

		

		'gii'=&gt;array(

			'class'=&gt;'system.gii.GiiModule',

			'password'=&gt;'admin',

			'generatorPaths'=&gt;array(

					'bootstrap.gii',

				),

		),

		

	),


	// application components

	'components'=&gt;array(

		'bootstrap'=&gt;array(

    		'class'=&gt;'ext.bootstrap.components.Bootstrap', // assuming you extracted bootstrap under extensions

         ),

		

		'user'=&gt;array(

			// enable cookie-based authentication

			'allowAutoLogin'=&gt;true,

			'class'=&gt;'RWebUser',

		),

		//


		

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

		'urlManager'=&gt;array(

			'urlFormat'=&gt;'path',

			'showScriptName'=&gt;false,

			'caseSensitive'=&gt;false,

			'rules'=&gt;array(

			),

		

		),

		

		'db'=&gt;array(

			'connectionString' =&gt; 'mysql:host=localhost;dbname=yii_tesis',

			'emulatePrepare' =&gt; true,

			'username' =&gt; 'root',

			'password' =&gt; '',

			'charset' =&gt; 'utf8',

		),

		

		'errorHandler'=&gt;array(

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

            'errorAction'=&gt;'site/error',

        ),

		'log'=&gt;array(

			'class'=&gt;'CLogRouter',

			'routes'=&gt;array(

				array(

					'class'=&gt;'CFileLogRoute',

					'levels'=&gt;'error, warning',

				),

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

				/*

				array(

					'class'=&gt;'CWebLogRoute',

				),

				*/

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()-&gt;params['paramName']

	'params'=&gt;array(

		// this is used in contact page

		'adminEmail'=&gt;'webmaster@example.com',

	),

);



And I used current version of Yii. Any suggestion?

Hi All,

Is there a way to remove the auto label in dropDownListRow function?

I tried to search it but i could not find a solution.

See screenshot below for reference.

3087

remove_label.jpg

Thanks in advance.

Setting label to false should do the trick.

It still infringes the Glyphicons Free license.

Hey ekerazha,

Thanks for notifying me about this. I’ll look into it as soon as possible and make the necessary changes.

Simply add "Icons from Glyphicons Free, licensed under CC BY 3.0." in the footer on each page where Glyphicons are used. The link to CC is not necessarily needed, I guess.

FontAwesome

Alternatively, one could use FontAwesome icons that are licensed under CC, too, and the author just wants a note in human-readable source code. It’s pretty straight forward how to replace the sprites; either via Less or CSS.

Font based icons can have issues on some browsers (I found some issues on the Android browser).

The extension will use image icons as long as Bootstrap does. I won’t make any changes to Bootstrap itself.

Hi. I have a problem with modal and BootButtonGroup

This is code from examples.


<?php $this->beginWidget('bootstrap.widgets.BootModal', array('id'=>'myModal')); ?>

 

<div class="modal-header">

    <a class="close" data-dismiss="modal">&times;</a>

    <h3>Modal header</h3>

</div>

 

<div class="modal-body">

    <p>One fine body...</p>

</div>

 

<div class="modal-footer">

    <?php $this->widget('bootstrap.widgets.BootButton', array(

        'type'=>'primary',

        'label'=>'Save changes',

        'url'=>'#',

        'htmlOptions'=>array('data-dismiss'=>'modal'),

    )); ?>

    <?php $this->widget('bootstrap.widgets.BootButton', array(

        'label'=>'Close',

        'url'=>'#',

        'htmlOptions'=>array('data-dismiss'=>'modal'),

    )); ?>

</div>

 

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

<?php $this->widget('bootstrap.widgets.BootButton', array(

    'label'=>'Open modal',

    'url'=>'#myModal',

    'type'=>'primary',

    'htmlOptions'=>array('data-toggle'=>'modal'),

)); ?>


<div class="btn-toolbar">

    <?php $this->widget('bootstrap.widgets.BootButtonGroup', array(

        'type'=>'primary',

        'buttons'=>array(

            array('label'=>'Action', 'items'=>array(

                array('label'=>'Open modal', 'url'=>'#myModal', 'htmlOptions'=>array('data-toggle'=>'modal'),),

                '---',

                array('label'=>'Test', 'url'=>'#'),

            )),

        ),

    )); ?>

</div>

I have changed only one thing in <div class="btn-toolbar">


array('label'=>'Open modal', 'url'=>'#myModal', 'htmlOptions'=>array('data-toggle'=>'modal'),),

When i click on button modal appears.

But when i click on "Open modal" item in ButtonGroup, nothing happens

Html generated by Yii bootstrap




<div class="btn-group">

    <a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Action <span class="caret"></span></a>

    <ul class="dropdown-menu">

        <li class=""><a href="#myModal">Open modal</a></li>

        <li class="divider"></li>

        <li class=""><a href="#">Test</a></li>

    </ul>

</div>

If I edit html via Firebug modal works fine


<li class=""><a href="#myModal"  data-toggle="modal">Open modal</a></li>

What i make wrong?

Not much wrong - just one common mistake:

Use ‘linkOptions’ instead of ‘htmlOptions’ and it should work fine.

Thank you!!!

Hello, you begin the implementation of multiple sub-navbar at 1.0, but then rolled, whether this function is implemented.