【问题标题】:Floating of labels not working in yii2浮动标签在 yii2 中不起作用
【发布时间】:2017-08-25 14:53:28
【问题描述】:

我在 yii2 basic 中创建了一个表单,并使用材料设计来启用浮动标签,但是当我单击输入字段时,它的标签不会浮动在上方。这是我的表单代码。

    <?php
    $form = ActiveForm::begin([
                'action' => ['index'],
                'method' => 'get',
    ]);
    ?>


    <div class="panel-body container-fluid">

        <div class="row">
            <div class="col-md-12">
                <div class="col-xs-6 col-lg-6">

                    <div class="form-group form-material floating" data-plugin="formMaterial">
                        <?= $form->field($model, 'corporation_name',[  'labelOptions' => [ 'class' => 'floating-label' ]])->textInput(['maxlength' => true, 'class' => 'form-control'])->label('Corporation Name') ?>    
                    </div>

                    <div class="form-group form-material floating" data-plugin="formMaterial">
                        <?= $form->field($model, 'user_first_name',[  'labelOptions' => [ 'class' => 'floating-label' ]])->textinput(['class' => 'form-control'])->label('Corporation Admin'); ?>
                    </div>
                </div>
                <div class="col-xs-6 col-lg-6">
                    <div class="form-group form-material floating" data-plugin="formMaterial">
                        <div class="example"> <b role="presentation"></b>
                            <?= $form->field($model, 'corporation_status')->dropDownList(Yii::$app->appstatues->status, ['prompt' => 'Status'])->label(false); ?>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-12">
                <div class="form-group form-material floating m-t-27" data-plugin="formMaterial">
                    <?= Html::submitButton('Search', ['class' => 'btn-primary btn waves-effect waves-light   waves-effect']) ?>
                    <?= Html::resetButton('Reset', ['class' => 'btn-primary btn waves-effect waves-light   waves-effect', 'onclick' => 'location.href = "/admin/corporations";']) ?>

                </div>
            </div>
        </div>

    </div>
    <?php ActiveForm::end(); ?>

</div>

谁能告诉我我做错了什么?

【问题讨论】:

  • 没有人会创建一个 Yii 应用来测试你的代码。此外,您没有指定您正在使用哪个材料设计库。但是,由于您的问题与前端有关,它始终是 HTML + CSS + JS,如果您在其中创建 minimal reproducible example,您将大大提高获得问题解答和问题修复的机会添加输出HTML 并链接适当的资源,以便可以在此处重现和检查问题。至少,请指定您正在使用的 MD 库。另外,它是否正确加载? (对于页面的其余部分,我的意思是)。

标签: php css forms yii2


【解决方案1】:

您查看过检查元素吗?

如果我理解你的话......

尝试删除输入表单周围的 div。当您为模型绑定表单时,您已经有围绕输入的 div。试试这个...

<?= $form->field($model, 'ime',['options'=>['class'=>'form-group form-material floating', 'data-plugin'=> 'formMaterial'], 'labelOptions' => [ 'class' => 'floating-label' ]])->textInput(['maxlength' => true, 'class' => 'form-control'])->label('Corporation Name') ?> 

【讨论】:

    猜你喜欢
    • 2018-09-24
    • 1970-01-01
    • 2020-04-26
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多