setting class attribute in form elements

37 views
Skip to first unread message

jon.w...@gmail.com

unread,
Jul 9, 2015, 8:28:47 PM7/9/15
to we...@googlegroups.com
I inherited a web.py application, and am trying to update the presentation using css.

To get the presentation I want from an input form, I need to set the 'class' attribute on a dropdown box. For example, from the python expression in a web.py file

web.form.Dropdown('choose one', [('option 1', '1'), ('option 2', '2'), ('option 3', '3'), ('option 4', '4')])

I would like to generate the following html:

<select class="my_custom_input" name="choose one" id="choose one">
       <option value="1">option 1</option>
       <option value="2">option 2</option>
       <option value="3">option 3</option>
       <option value="4">option 4</option>
</select>

where the 'class="my_custom_input" attribute is added to the select element.  Right now, despite a lot of searching through the documentation I don't see a way to do that.  

Can anyone help with this?

Thanks,

Christophe

unread,
Jul 10, 2015, 2:25:14 AM7/10/15
to we...@googlegroups.com
Hello Jon,

this should do the trick:


web.form.Dropdown('choose one',
                                  [  ('option 1', '1'),
                                     ('option 2', '2'),
                                     ('option 3', '3'),
                                     ('option 4', '4')],
                                  class_="YourBelovedClass")

For other features, you can read http://webpy.org/form, section «input features».

Regards,

Christophe.
--
You received this message because you are subscribed to the Google Groups "web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webpy+un...@googlegroups.com.
To post to this group, send email to we...@googlegroups.com.
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages