Code

Opened 7 years ago

Closed 7 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: UI/UX:

Description

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.

Attachments (0)

Change History (6)

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 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 7 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 7 years ago by anonymous

  • Resolution set to wontfix
  • Status changed from new to closed

comment:5 Changed 7 years ago by SmileyChris

  • Resolution wontfix deleted
  • Status changed from closed to reopened

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 7 years ago by ubernostrum

  • Resolution set to duplicate
  • Status changed from reopened to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.