Previously, the generation of dataset attributes when passing true or false, converted to 1 or 0. Now the logic has changed. Maybe worth a review #17625?
echo Html::tag('div', 'TEST', ['data' => ['id' => 'main_div', 'test' => true]]);
generate HTML code
<div data-id="main_div" data-test="1">TEST</div>
TRUE
echo Html::tag('div', 'TEST', ['data' => ['id' => 'main_div', 'test' => true]]);
generate HTML code
<div data-id="main_div" data-test="">TEST</div>
FALSE
echo Html::tag('div', 'TEST', ['data' => ['id' => 'main_div', 'test' => false]]);
generate HTML code
<div data-id="main_div">TEST</div>
| Q | A
| ---------------- | ---
| Yii version | 2.0.32
| PHP version | 7.3.11
| Operating system | Unix
I fix it
elseif (is_bool($v)) {
if ($v) {
$html .= " $name-$n=" .$v;
}
}
Do you need the 1/0 on the attribute?
You could pass an int/string to get a value.
The new logic provides for the presence of the attribute itself. It breaks backward compatibility
I'd say the update brings it into line with the html spec, https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attribute
@s1lver even if it does, it was released in 2.0.29. It's three versions ago so already adopted. Reverting it would be backwards compatibility break as well. What we can do is adding a note to UPGRADE.
Ok
Most helpful comment
@s1lver even if it does, it was released in 2.0.29. It's three versions ago so already adopted. Reverting it would be backwards compatibility break as well. What we can do is adding a note to UPGRADE.