pugjs - radio button checked attribute as variable

399 Views Asked by At

Working on a pugjs mixin. Creating radio buttons in a loop over json. Normal name-value pairs are work as expected. In the loop, setting a radio button to checked by default is fine. Trying to figure out how to not set the checked value for non-selected radio buttons.

I can do this with javascript but seems like I should be able to do this in pug.

Tried setting a variable

-checked =(!fVar.checked)?'checked':''

and then use in tag

input(type='radio' #{checked})

Is there a way to do this in pug?

1

There are 1 best solutions below

0
Pat Sanders On

Figured out one way. Not as direct as I would like but I nested mixins. The main mixin has a case statement that calls child mixins.

case fVar.checked
            when 'true'
                +radioChecked()
            when 'false'
                +radioUnchecked()

Not very D.R.Y. but it works.