Jade: how does one assign the 'checked' attribute to dynamically generated radio button inputs?
Asked Answered
T

1

9

I'm using Jade templates in an edit view where I edit a user's details, and a dynamically generated radio button like so (comes from my mongodb):

li Role:
      br
      label Subscriber
      input(type="radio", name="user[role]", val="subscriber")
      br
      label Admin
      input(type="radio", name="user[role]", val="admin")
      br
      label Super Admin
      input(type="radio", name="user[role]", val="superadmin")

How do I set one to checked dynamically?

So if in my db, my role is subscriber , how do I check for that? "Normally", I would do a if(user.role == 'subscriber'){'checked'} and so on for all of the different values.

Where/how does that logic go into this bit of Jade?

Trenatrenail answered 16/4, 2012 at 15:57 Comment(0)
C
14

input(type ='radio', name=user[role], checked)

To dynamically check, see examples below:

input(type ='radio', name=user[role], checked=true)   
input(type ='radio', name=user[role], checked=false)   
input(type ='radio', name=user[role], checked=role=='user')
Chute answered 5/5, 2012 at 18:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.