如何在 Yii2 中使用 .form-group 禁用换行复选框
How to disable wrap checkbox with .form-group in Yii2
如何使用 yii\bootstrap\ActiveForm 在 Yii2 中使用 div.form-组禁用换行复选框?
我需要的(AdminLTE登录页面模板):
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> Remember Me
</label>
</div>
</div>
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</div>
我试过了:
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
...
<div class="row">
<div class="col-xs-8">
<?= $form->field($model, 'rememberMe')->checkbox(); ?>
</div>
<div class="col-xs-4">
<?= Html::submitButton('Sign In', ['class' => 'btn btn-primary btn-block btn-flat', 'name' => 'login-button']); ?>
</div>
</div>
<?php ActiveForm::end(); ?>
它呈现为:
<div class="row">
<div class="col-xs-8">
<div class="form-group field-loginform-rememberme">
<div class="checkbox">
<label>
<input type="checkbox" name="LoginForm[rememberMe]" value="0"> Remember Me
</label>
<p class="help-block help-block-error"></p>
</div>
</div>
</div>
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</div>
一切都很好,除了额外的包装纸 <div class="form-group field-loginform-rememberme">
如何删除这个额外的包装?
我做到了
对于正在寻找的人:
<div class="row">
<?= $form->field($model, 'rememberMe',['options' => ['class' =>'col-xs-8']])->checkbox(); ?>
</div>
<div class="col-xs-4">
// ...
它将用 div.col-sx-8
换行
$form->field($model,'field',[
'options'=>
[
'tag'=>'div',
'class'=>'checkbox icheck'
]
]
)->checkbox();
或者你可以用下一种方法
$field = $form->field($model,'field',[
'options'=>
[
'tag'=>'div',
'class'=>'checkbox icheck'
],
'selectors'=>[
'error'=>'span.error'
]
]
);
echo $field->begin();
?>
<label><?php
echo \yii\helpers\Html::activeCheckbox($model,'field');
?></label>
<?php
echo \yii\helpers\Html::error($model,'field',
['class'=>'error','tag'=>'span' ]);
<?php
echo $field->end();
像这样。
$form->field($item, "[$i]selected")->checkBox()->label(false)
不适用于复选框,但以下内容有效:
<?= $form->field($item, "[$i]selected")->checkBox(['label'=>'']);?>
或
<?= $form->field($item, "[$i]selected")->checkBox(['label'=>null]);?>
如何使用 yii\bootstrap\ActiveForm 在 Yii2 中使用 div.form-组禁用换行复选框?
我需要的(AdminLTE登录页面模板):
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> Remember Me
</label>
</div>
</div>
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</div>
我试过了:
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
...
<div class="row">
<div class="col-xs-8">
<?= $form->field($model, 'rememberMe')->checkbox(); ?>
</div>
<div class="col-xs-4">
<?= Html::submitButton('Sign In', ['class' => 'btn btn-primary btn-block btn-flat', 'name' => 'login-button']); ?>
</div>
</div>
<?php ActiveForm::end(); ?>
它呈现为:
<div class="row">
<div class="col-xs-8">
<div class="form-group field-loginform-rememberme">
<div class="checkbox">
<label>
<input type="checkbox" name="LoginForm[rememberMe]" value="0"> Remember Me
</label>
<p class="help-block help-block-error"></p>
</div>
</div>
</div>
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</div>
一切都很好,除了额外的包装纸 <div class="form-group field-loginform-rememberme">
如何删除这个额外的包装?
我做到了
对于正在寻找的人:
<div class="row">
<?= $form->field($model, 'rememberMe',['options' => ['class' =>'col-xs-8']])->checkbox(); ?>
</div>
<div class="col-xs-4">
// ...
它将用 div.col-sx-8
换行$form->field($model,'field',[
'options'=>
[
'tag'=>'div',
'class'=>'checkbox icheck'
]
]
)->checkbox();
或者你可以用下一种方法
$field = $form->field($model,'field',[
'options'=>
[
'tag'=>'div',
'class'=>'checkbox icheck'
],
'selectors'=>[
'error'=>'span.error'
]
]
);
echo $field->begin();
?>
<label><?php
echo \yii\helpers\Html::activeCheckbox($model,'field');
?></label>
<?php
echo \yii\helpers\Html::error($model,'field',
['class'=>'error','tag'=>'span' ]);
<?php
echo $field->end();
像这样。
$form->field($item, "[$i]selected")->checkBox()->label(false)
不适用于复选框,但以下内容有效:
<?= $form->field($item, "[$i]selected")->checkBox(['label'=>'']);?>
或
<?= $form->field($item, "[$i]selected")->checkBox(['label'=>null]);?>