Opened 8 years ago

Closed 4 years ago

#4341 closed (worksforme)

SelectDateWidget does not pass through attrs

Reported by: Peter Reeves <oneofthemany1@…> Owned by: alexr
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:

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@…> 8 years ago.
Patch generated using "diff -Naur"
tests.py (444 bytes) - added by alexr 4 years ago.
A unit test that shows this problem has been fixed

Download all attachments as: .zip

Change History (11)

comment:1 Changed 8 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

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

Patch generated using "diff -Naur"

comment:2 Changed 8 years ago by adrian

  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 8 years ago by lasturi_younes@…

  • Cc ngf added
  • Needs tests unset
  • Patch needs improvement set

dddddddddddddddd

comment:4 Changed 8 years ago by John Shaffer <jshaffer2112@…>

  • Cc ngf removed
  • Needs tests set
  • Patch needs improvement unset

comment:5 Changed 7 years ago by dakrauth

  • Cc oneofthemany1@… added
  • Owner changed from nobody to dakrauth

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

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

comment:7 Changed 5 years ago by adamnelson

  • Patch needs improvement set

comment:8 Changed 4 years ago by alexr

  • Owner changed from dakrauth to alexr

Changed 4 years ago by alexr

A unit test that shows this problem has been fixed

comment:9 Changed 4 years ago by alexr

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

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