Christian Joergensen wrote: >>> Is it possible to have css classes attached to newforms widgets? I would >>> like to be able to distinguish between fx. checkboxes, radio buttons, >>> submit buttons, text fields (which are all <input />'s). > >> well, you can pass args={'class' : 'whatever'} to the widget's __init__() >> or you could subclass the widget and do that inside > > This does (IMHO) not comply very much with the DRY philosophy of django. > >> but there is currently no class set globally for all widgets >> >>> In the oldforms module when having a required charfield, there would be >>> a class="vTextField required" to make CSS styling easier. >>> >>> Am I overlooking something, or is newforms missing this? > > I was able to hack newforms by adding this in the __init__ of Field:
I actually went a little further and hacked an extension for newforms to accomplish this. Furthermore it will allow for layout definitions using fieldsets and YUI grids: http://www.djangosnippets.org/snippets/214/ An example using a fieldset and two columns: class MyForm(WTForm): name1 = forms.CharField(label="Name (1)") email1 = forms.EmailField(label="E-mail address (1)") name2 = forms.CharField(label="Name (2)") email2 = forms.EmailField(label="E-mail address (2)") class Meta: layout = (Fieldset("Person details", Columns(("name1", "name2"), ("email1", "email2"))),) This will result in the form layout of: +-[ Person details ]----------------------------------+ |+-------------------------+-------------------------+| || Name (1) | E-mail address (1) || || [_____________________] | [_____________________] || || | || || Name (2) | E-mail address (2) || || [_____________________] | [_____________________] || |+-------------------------+-------------------------+| +-----------------------------------------------------+ -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info
signature.asc
Description: OpenPGP digital signature