Reputation: 17505
How to force Yii 1.x to render HTML5's attribute without value, like autofocus
or readonly
in htmlOptions
array passed to anything? So, as a result I'd get for example:
<input autofocus>
I tried this idea of setting array('autofocus'=>TRUE);
or array('autofocus'=>'autofocus');
, but this does not work. It renders either <field autofocus="1">
or <field autofocus="autofocus">
and both are not, what HTML5 expects, so they don't work.
I also tried (I don't know, why did I expect this to work) array('autofocus'=>NULL);
, but such attributes are now removed by Yii 1.x and are not rendered at all.
I also tried a stupid workaround of setting this value using jQuery. But, that scares me even, if I think about it. There's got to be a better solution to this.
This seemed obvious, but I failed on finding proper answer, here on in other sources.
Upvotes: 1
Views: 472
Reputation: 4654
I've just found out that it's possible in some way. All modern browsers treat following lines equally:
<input autofocus>
<input autofocus="autofocus">
So, basically, you cannot add key-only attribute to Yii, but you can add either 'autofocus' => 'autofocus'
or 'autofocus' => true
and it will behave in the same way. And it works for CHtml::activeTextField
as well as for usual input
.
Upvotes: 1
Reputation: 17505
According to Maurizio Domba Cerin, a Yii Framework 1.x forum admin, you should use property CHtml::renderSpecialAttributesValue
(available since Yii 1.1.13) like this (set it to FALSE
):
CHtml::$renderSpecialAttributesValue = FALSE;
This will tell CHtml
class to render all fields' attributes without value in the way, it was introduced in HTML5 (i.e. <input autofocus>
) instead of "old" XHTML way (<input autofocus="autofocus"
).
Upvotes: 1
Reputation: 8033
I think you can't do this with yii. You need to implement this by yourself. Yii provides CActiveForm#textField
for normal use and you need to use text field in advanced mode. I think there is no way for doing this, except writing plain html <input>
tag. You can write html <input>
and assign id and name similar to yii.
Upvotes: 1