#4341 closed (worksforme)
SelectDateWidget does not pass through attrs
| Reported by: | 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)
Change History (9)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
| Needs tests: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Looks like a good fix, but it needs unit tests before we can check it in.
comment:5 by , 18 years ago
| Cc: | added |
|---|---|
| Owner: | changed from to |
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 , 18 years ago
The patch for #6230 addresses this ticket as well, although I won't necessarily call this a duplicate.
comment:7 by , 16 years ago
| Patch needs improvement: | set |
|---|
comment:8 by , 15 years ago
| Owner: | changed from to |
|---|
comment:9 by , 15 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → 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.
Can you please attach the patch as an attachment, so that we can more easily check and apply it? Thanks.