andrzej1_1
(Andrzej1 1)
January 30, 2016, 7:57pm
1
Hello. I have form, which is hard to generate with field() , because layout contains a lot of html between label, input and error. Instead of fighting with template option, in Yii1 I could use CHtml::activeTextField , CHtml::activeLabel and form was normally working with validation. How I can do it in Yii2?
hrnair
(Harikrishnan Hr)
January 31, 2016, 2:10am
2
andrzej1_1:
Hello. I have form, which is hard to generate with field() , because layout contains a lot of html between label, input and error. Instead of fighting with template option, in Yii1 I could use CHtml::activeTextField , CHtml::activeLabel and form was normally working with validation. How I can do it in Yii2?
Yii2 Active fields are wrapped in bootstrap. Perhaps you can use the activeform itself and get the desired layout.
softark
(Softark)
January 31, 2016, 7:15am
3
activeLabel(), activeTextInput() and likes are implemented in yii\helpers\Html. They are the equivalents of CHtml::activeXXXX in Yii 1.1.
Please refer to the API documentation of yii\helpers\Html.
http://www.yiiframework.com/doc-2.0/yii-helpers-html.html
The extended yii\bootstrap\(Base)Html also supports them just with the same name and the signatures.
andrzej1_1
(Andrzej1 1)
January 31, 2016, 9:37am
4
Referring to this: https://github.com/yiisoft/yii2/issues/3237 client-side validation will not work and this is by design. Maybe there is another way?
Edit
I found solution here: http://stackoverflow.com/questions/24698403/how-to-display-only-label-and-error-for-activefield-in-yii2
echo $form->field($model, 'fieldname')->begin();
echo Html::activeLabel($model,'fieldname');
echo Html::activeTextInput($model, 'fieldname');
echo Html::error($model,'fieldname', ['class' => 'help-block']);
echo $form->field($model, 'fieldname')->end();
I think this is important and should be mentioned in docs.