Opened 12 years ago

Closed 12 years ago

#4005 closed (duplicate)

Add "class=<field name>" attribute to generated inputs

Reported by: tonnzor <tonn81@…> Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It would be very useful if each generated input was marked - what kind of data it contains. Then it is possible to improve the look and feel of elements via CSS or JS.

For example, if all newforms.IntegerFields has 'integer' class, it would be easy to align text to the right, make the font monospace, decrease the size, etc.

If the bug is approved, I can write a patch.

Change History (6)

comment:1 Changed 12 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 12 years ago by Terry

+1 for this change.

IMO it should be done as an optional string in the Fields initiation parameters called 'class', e.g.

My_int = newforms.IntegerField(label="Your income in cold cash", class="Income dollars")

This would allow quite some flexibility when styling the form.

comment:3 Changed 12 years ago by anonymous

This is possible with attrs for the widget, which makes sense, since the widget is associated with how the field looks. For example:

    my_int = newforms.IntegerField(label = "Your income in cold cash", 
                                   widget = forms.TextInput(attrs={'class': "Income dollars"}),

You can pass any dictionary for attrs, so dynamically determining and specifying attributes is easy.

comment:4 Changed 12 years ago by anonymous

Resolution: wontfix
Status: newclosed

comment:5 Changed 12 years ago by Chris Beaven

Resolution: wontfix
Status: closedreopened

anonymous, don't close tickets thanks - that's a job for one of the ticket managers.

Specifically, you're missing the point in this ticket which is to automatically add the field's identity to the class attr (like oldforms does with vHidden, vTextArea, etc)

comment:6 Changed 12 years ago by James Bennett

Resolution: duplicate
Status: reopenedclosed

The attrs trick is one solution, but either #3515 or #3512 would solve the underlying problem of automatically marking things in the HTML.

Note: See TracTickets for help on using tickets.
Back to Top