Opened 10 years ago

Closed 6 years ago

Last modified 6 days ago

#4341 closed (worksforme)

SelectDateWidget does not pass through attrs

Reported by: Peter Reeves <oneofthemany1@…> Owned by: Alex Robbins
Component: Forms Version: master
Severity: Keywords: SelectDateWidget attrs
Cc: oneofthemany1@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:


Using the following code, the output html omits any attributes passed to it.

DataForm.base_fields['dob'].widget = extras.SelectDateWidget(years=range(2007,1899,-1),attrs={'class':'dobclass' })

Below is the output from diff for a patch to django\newforms\extras\

However this does not allow the setting of different attributes per select option.

<         select_html = Select(choices=month_choices).render(self.month_field % name, month_val)
>         select_html = Select(choices=month_choices).render(self.month_field % name, month_val, attrs=self.attrs)
<         select_html = Select(choices=day_choices).render(self.day_field % name, day_val)
>         select_html = Select(choices=day_choices).render(self.day_field % name, day_val, attrs=self.attrs)
<         select_html = Select(choices=year_choices).render(self.year_field % name, year_val)
>         select_html = Select(choices=year_choices).render(self.year_field % name, year_val, attrs=self.attrs)

Attachments (2)

4341-patch.txt (1.1 KB) - added by Peter Reeves <oneofthemany1@…> 10 years ago.
Patch generated using "diff -Naur" (444 bytes) - added by Alex Robbins 6 years ago.
A unit test that shows this problem has been fixed

Download all attachments as: .zip

Change History (9)

comment:1 Changed 10 years ago by Malcolm Tredinnick

Can you please attach the patch as an attachment, so that we can more easily check and apply it? Thanks.

Changed 10 years ago by Peter Reeves <oneofthemany1@…>

Attachment: 4341-patch.txt added

Patch generated using "diff -Naur"

comment:2 Changed 10 years ago by Adrian Holovaty

Needs tests: set
Triage Stage: UnreviewedAccepted

Looks like a good fix, but it needs unit tests before we can check it in.

comment:5 Changed 9 years ago by David A Krauth

Cc: oneofthemany1@… added
Owner: changed from nobody to David A Krauth

The first patch doesn't seem sufficient to meet the requirement that of handling attrs passed to render() should override self.attrs.

For instance, in MultiWidget.render(), each widget component is passed the result of:

final_attrs = self.build_attrs(attrs).

comment:6 Changed 9 years ago by Matt McClanahan

The patch for #6230 addresses this ticket as well, although I won't necessarily call this a duplicate.

comment:7 Changed 7 years ago by Adam Nelson

Patch needs improvement: set

comment:8 Changed 6 years ago by Alex Robbins

Owner: changed from David A Krauth to Alex Robbins

Changed 6 years ago by Alex Robbins

Attachment: added

A unit test that shows this problem has been fixed

comment:9 Changed 6 years ago by Alex Robbins

Resolution: worksforme
Status: newclosed

I can't reproduce this issue. I attached a test that verifies a class attr does show up in the render method. Closing this as worksforme.

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