简体   繁体   English

Yii2 textInput +标签隐藏

[英]Yii2 textInput + label hidden

I would like to have a textInput with a label hidden , what I would like to show later via onChange. 我想有一个带有隐藏标签的textInput ,我想稍后通过onChange显示。 I have searched quite a lot, but found nothing. 我已经搜索了很多,但是什么也没找到。 Either I turn it off with ->label(false) , or leave it on. 我可以通过->label(false)将其关闭,或者将其保持打开状态。 Is there a way to implement ->label(['style' => 'display: none']) somehow, as it's working with ->textInput(['style' => 'display: none']) ? 有没有办法以某种方式实现->label(['style' => 'display: none']) ,因为它与->textInput(['style' => 'display: none'])

Thank you. 谢谢。

The first argument of ActiveField::label() method is the string used as label, the second one is options. ActiveField::label()方法的第一个参数是用作标签的字符串,第二个参数是选项。 You can pass null in first argument to let the ActiveField widget use getAttributeLabel() method of your model. 您可以在第一个参数中传递null,以使ActiveField小部件使用模型的getAttributeLabel()方法。

The code should look like this: 该代码应如下所示:

$form->field($model, 'attribute')->label(null, ['style' => 'display: none']);

Or you can pass options to label directly from field method like this: 或者,您可以传递选项以直接从字段方法进行标记,如下所示:

$form->field($model, 'attribute', ['labelOptions' => ['style' => 'display: none']]);

The easiest way: 最简单的方法:

$form->field($model, 'attribute')->label(false);

Hope it will helps. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM