Opened 17 years ago

Closed 14 years ago

Last modified 8 years ago

#4341 closed (worksforme)

SelectDateWidget does not pass through attrs

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

Description

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\widgets.py:

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

43c43
<         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)
47c47
<         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)
51c51
<         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@…> 17 years ago.
Patch generated using "diff -Naur"
tests.py (444 bytes ) - added by Alex Robbins 14 years ago.
A unit test that shows this problem has been fixed

Download all attachments as: .zip

Change History (9)

comment:1 by Malcolm Tredinnick, 17 years ago

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

by Peter Reeves <oneofthemany1@…>, 17 years ago

Attachment: 4341-patch.txt added

Patch generated using "diff -Naur"

comment:2 by Adrian Holovaty, 17 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

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

comment:5 by David A Krauth, 17 years ago

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 by Matt McClanahan, 17 years ago

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

comment:7 by Adam Nelson, 15 years ago

Patch needs improvement: set

comment:8 by Alex Robbins, 14 years ago

Owner: changed from David A Krauth to Alex Robbins

by Alex Robbins, 14 years ago

Attachment: tests.py added

A unit test that shows this problem has been fixed

comment:9 by Alex Robbins, 14 years ago

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