【问题标题】:Form inside TbNavbar Dropdown Items YiiBooster表单在 TbNavbar 下拉项目 YiiBooster
【发布时间】:2013-07-22 19:07:34
【问题描述】:

我正在开发 Yii 框架和 Yii Booster 扩展作为引导程序。我正在尝试在下拉列表中创建登录表单。我有一个 TbNavbar,上面是下拉代码,但是当我在下拉列表中添加登录表单时,它只显示下拉列表中的代码。

我以这篇文章为指导:

这是我的表单代码,但它不起作用:

<?php  $this->beginWidget('bootstrap.widgets.TbNavbar', array(
'type'=>'inverse',
'brand' => 'Title',  
'fixed'=>'bottom',  
'collapse'=>true,  
'items'=>array(
array(
  'class'=>'bootstrap.widgets.TbMenu',
  'type'=>'inverse',
  'items'=>array(
    array('label'=>'Home', 'url'=>'#', 'active'=>true),
    array('label'=>'Link', 'url'=>'#'),
    array('label' => 'DropDown', 'items' => array(
          array('label' => 'Item1', 'content' => 'Item1 Content'),
          array('label' => 'Item2', 'content' => 'Item2 Content')
        )),
    array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(
      array('label'=>'Action', 'url'=>'#'),
      array('label'=>'Another action', 'url'=>'#'),
      array('label'=>'Something else here', 'url'=>'#'),
      '---',
      array('label'=>'NAV HEADER'),
      array('label'=>'Separated link', 'url'=>'#'),
      array('label'=>'One more separated link', 'url'=>'#'),


    )),
  ),
),


'<ul class="nav pull-right">
               <li><a href="/users/sign_up">Sign Up</a></li>
               <li class="divider-vertical"></li>
               <li class="dropdown">
                   <a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <strong class="caret"></strong></a>
                   <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
                       <?php $form = $this->beginWidget(\'bootstrap.widgets.TbActiveForm\', array(
                          \'id\'=>\'verticalForm\',
                          \'htmlOptions\'=>array(\'class\'=>\'well\'),
                      )); ?>

                      <?php echo $form->textFieldRow($model, \'textField\', array(\'class\'=>\'span3\')); ?>
                      <?php echo $form->passwordFieldRow($model, \'password\', array(\'class\'=>\'span3\')); ?>
                      <?php echo $form->checkboxRow($model, \'checkbox\'); ?>
                      <?php $this->widget(\'bootstrap.widgets.TbButton\', array(\'buttonType\'=>\'submit\', \'label\'=>\'Login\')); ?>

                      <?php $this->endWidget(); ?>
                    </div>
               </li>
           </ul>'  ),)); ?>
<?php $this->endWidget(); ?>

【问题讨论】:

    标签: twitter-bootstrap frameworks yii yii-booster


    【解决方案1】:

    试试这样。它对我有用

            <?php
            $this->beginWidget('bootstrap.widgets.TbNavbar', array(
                'type' => 'inverse',
                'brand' => 'Title',
                'fixed' => 'bottom',
                'collapse' => true,
                'items' => array(
                    array(
                        'class' => 'bootstrap.widgets.TbMenu',
                        'type' => 'inverse',
                        'items' => array(
                            array('label' => 'Home', 'url' => '#', 'active' => true),
                            array('label' => 'Link', 'url' => '#'),
                            array('label' => 'DropDown', 'items' => array(
                                    array('label' => 'Item1', 'content' => 'Item1 Content'),
                                    array('label' => 'Item2', 'content' => 'Item2 Content')
                            )),
                            array('label' => 'Dropdown', 'url' => '#', 'items' => array(
                                    array('label' => 'Action', 'url' => '#'),
                                    array('label' => 'Another action', 'url' => '#'),
                                    array('label' => 'Something else here', 'url' => '#'),
                                    '---',
                                    array('label' => 'NAV HEADER'),
                                    array('label' => 'Separated link', 'url' => '#'),
                                    array('label' => 'One more separated link', 'url' => '#'),
                            )),
                        ),
                    ),
                    '<ul class="nav pull-right">
                <li><a href="/users/sign_up">Sign Up</a></li>
                <li class="divider-vertical"></li>
                <li class="dropdown">
                    <a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <strong class="caret"></strong></a>
                    <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">' . html($this,$model) . '</div>
                </li>
            </ul>'),
                    )
            );
            ?>
            <?php $this->endWidget(); ?>
    

    函数定义

        <?php
        function html($obj,$model)
        {
            $html='';
            $form = $obj->beginWidget('bootstrap.widgets.TbActiveForm', array(
                'id' => 'verticalForm',
                'htmlOptions' => array('class' => 'well')
                    ));
            $html.=$form->textFieldRow($model, 'textField', array('class' => 'span3'));
            $html.=$form->passwordFieldRow($model, 'password', array('class' => 'span3'));
            $html.=$form->checkboxRow($model, 'checkbox');
            $html.=CHtml::submitButton('Login',array('class'=>'btn btn-info'));    
            $obj->endWidget();
    
            return $html;
        }
        ?>
    

    编辑:: 根据下面的评论

    当您在下拉内容中工作时,您可以停止 Bootstrap Drop-down 的默认传播。

            <script type="text/javascript">
                $(document).ready(function()
                {        
                    $('.dropdown-menu').click(function(e)
                    {            
                        e.stopPropagation();            
                    }); 
                });
            </script>
    

    【讨论】:

    • 谢谢!它现在在下拉列表中,但是当我单击按钮时,不执行任何操作:c 除此之外,我还有一些代码可以停止在 thextfields 和“登录按钮”上进行 ptopagation,因为当您单击下拉列表中的某些内容时无缘无故的躲起来。这可能是个问题吗?
    • @AareelyCoca,请检查编辑以解决您面临的下拉问题。
    • 好的,我有你放在这里的所有代码,当我点击按钮时它什么也没做:c 会不会是我缺少的其他东西?
    【解决方案2】:

    将此代码放在您的主要布局头中。这将加载 javascript,并且菜单应该可以使用它。

    <?php Yii::app()->bootstrap->registerAssetJs('');?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      • 2019-09-11
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      相关资源
      最近更新 更多