gvanto
(Gvanto)
January 13, 2016, 4:35am
1
I have some below:
<?= $form->field($model, 'phone_no')
->textInput(['placeholder'=>'(Conditionally validated based on checkbox above, groovy!)']) ?>
Which results in 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>
My Question is:
How can I add a class ‘invisible’ to the outer div (containing class=form-group currently) ?
Thanks for help
softark
(Softark)
January 13, 2016, 11:14am
2
Check ActiveForm::form() method in the API reference.
http://www.yiiframework.com/doc-2.0/yii-widgets-activeform.html
Probably:
<?= $form->field($model, 'phone_no', ['class' => 'invisible form-group'])
...
Hmm, I’m not very sure whether we have to add ‘form-group’ or not.
regist70
(regist70)
April 13, 2021, 10:43am
4
Unfortunately, doesnt works
echo $form->field($model, 'email', ['class' => 'form-group'])->textInput(['autocomplete'=>"off"])->label( $emailLabel );
softark
(Softark)
April 13, 2021, 1:38pm
5
Hi @regist70 ,
It looks very strange. Could you give us the stack trace?
(No image preferred. Text please)
regist70
(regist70)
April 15, 2021, 3:50pm
6
Deleted everything but broken code
use yii\helpers\Html;
//use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
echo '<div class="user-form">';
$form = ActiveForm::begin([]);
//echo $form->field($model, 'email')->textInput(['autocomplete'=>"off",'maxlength' => true]);
echo $form->field($model, 'email', ['class' => 'form-group'])->textInput(['autocomplete'=>"off"])->label( $emailLabel );
echo '<div class="form-group">';
echo Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']);
echo '</div>';
ActiveForm::end();
echo '</div>';
Still have error
Preformatted text # Not instantiable – [yii\di\NotInstantiableException](http://www.yiiframework.com/doc-2.0/yii-di-notinstantiableexception.html)
## Failed to instantiate component or class "form-group".
## Caused by: ReflectionException
### Class form-group does not exist
in G:\WebServers7.4\home\wash\www\vendor\yiisoft\yii2\di\Container.php at line 508
Full page with error report https://dropmefiles.com/C4wba
1 Like
softark
(Softark)
April 16, 2021, 11:03am
7
Hi @regist70 ,
softark:
<?= $form->field($model, 'phone_no', ['class' => 'invisible form-group'])
I’m very sorry. I was wrong.
Try this instead:
$form->field($model, 'email', ['options' => ['class' => 'invisible']])-> ...
The 3rd parameter of ActiveForm::field()
is:
and so we have to use ActiveField::options
to set the html attributes (e.g. ‘class’) of the field div.
1 Like
regist70
(regist70)
April 16, 2021, 11:35am
8
Yes, this is works.
Thank you.
EspinoVic
(Victor Espino)
November 13, 2022, 5:10am
9
this way worked for me.
Instead passing $options, i used the array [‘options’ => […] ]