CheckboxList: What is? or : in attributes for Nette\Utils\Html?

dakur
Member | 493
+
0
-

Nette\Forms\Controls\CheckboxList#getControl() has some strange characters ? or : at the end of its attribute names but I can not find a mention anywhere about what it does – neither in docs nor in the code. Can someone explain it to me, please? Thanks.

E.g. 'checked?' => $this->value

https://imgur.com/a/xeKc4U6

Last edited by dakur (2020-03-31 11:10)

nightfish
Member | 517
+
0
-

These modifiers are processed in https://github.com/…/Helpers.php#L207
It looks like merging default values of attributes with user-supplied ones.

EDIT: I am sorry, this post was initially written in Czech, b/c I overlooked we are in the English part of the forum.

Last edited by nightfish (2020-03-31 12:04)

jiri.pudil
Nette Blogger | 1029
+
0
-

Such attributes are dynamic, i.e. their value varies for each input in the list. The difference is that ? expects a list of input values for which the attribute is true, while : expects an array of input value => attribute value pairs.

Perhaps the test can explain it better than me :)

dakur
Member | 493
+
0
-

Magic ✨ Thank you for your answers – both link to source code which I was unable to find and a reminder that tests exist. :-)

dakur
Member | 493
+
+1
-

For completeness – it is now stated in docs: https://doc.nette.org/…ms/rendering#… and it works everywhere with attributes (not only setHtmlAttribute()).

Last edited by dakur (2021-06-10 11:30)