我有一些代码如下:
<?= $form->field($model,'phone_no')->textInput( [ 'placeholder' => '(Conditionally validated based on checkBox above,groovy!)' ] ) ?>
哪些导致HTML:
<div class="form-group field-contactform-phone_no"> <label class="control-label">Phone No <input type="text" aria-describedby="hint-contactform-phone_no" placeholder="(Conditionally validated based on checkBox above,groovy!)" name="ContactForm[phone_no]" id="contactform-phone_no" class=""></label> <small class="error-Box"></small> <p class="help-text" id="hint-contactform-phone_no"></p> </div>
我的问题是:
如何添加一个类’invisible’到外部div(目前包含class = form-group)?
感谢帮助
你可以这样做单字段:
<?= $form->field($model,'phone_no',['options' => ['class' => 'form-group invisible']) ->textInput(['placeholder' => '(Conditionally validated based on checkBox above,groovy!)']) ?>
全局(对于表单中的所有字段)可能是这样的:
<?PHP $form = ActiveForm::begin([ 'fieldConfig' => ['options' => ['class' => 'form-group invisible']],]); ?>
您还可以有条件地构建fieldConfig:
<?PHP $form = ActiveForm::begin([ 'fieldConfig' => function ($model,$attribute) { if (...) { return ['options' => ['class' => 'form-group invisible']],} },]); ?>
官方文件:
> yii\widgets\ActiveField $options
> yii\widgets\ActiveForm $fieldConfig