Code

Opened 5 years ago

Closed 3 years ago

#12073 closed New feature (fixed)

AdminDateWidget and AdminTimeWidget not passing though additional attrs

Reported by: elliss Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords: widgets date time calendar
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by kmtracey)

Suggest a change to allow additional user-defined attributes to be passed though. currently they're passed in but not though:

CURRENT:

class AdminDateWidget(forms.TextInput):
    class Media:
        js = (settings.ADMIN_MEDIA_PREFIX + "js/calendar.js",
              settings.ADMIN_MEDIA_PREFIX + "js/admin/DateTimeShortcuts.js")

    def __init__(self, attrs={}):
        super(AdminDateWidget, self).__init__(attrs={'class': 'vDateField', 'size': '10'})

class AdminTimeWidget(forms.TextInput):
    class Media:
        js = (settings.ADMIN_MEDIA_PREFIX + "js/calendar.js",
              settings.ADMIN_MEDIA_PREFIX + "js/admin/DateTimeShortcuts.js")

    def __init__(self, attrs={}):
        super(AdminTimeWidget, self).__init__(attrs={'class': 'vTimeField', 'size': '8'})

SUGGESTED:

class AdminDateWidget(forms.TextInput):
    class Media:
        js = (settings.ADMIN_MEDIA_PREFIX + "js/calendar.js",
              settings.ADMIN_MEDIA_PREFIX + "js/admin/DateTimeShortcuts.js")

    def __init__(self, attrs={}):
        attrs.update({'class': 'vDateField', 'size': '10'})
        super(AdminDateWidget, self).__init__(attrs=attrs)

class AdminTimeWidget(forms.TextInput):
    class Media:
        js = (settings.ADMIN_MEDIA_PREFIX + "js/calendar.js",
              settings.ADMIN_MEDIA_PREFIX + "js/admin/DateTimeShortcuts.js")

    def __init__(self, attrs={}):
        attrs.update({'class': 'vTimeField', 'size': '8'})
        super(AdminTimeWidget, self).__init__(attrs=attrs)

Attachments (1)

12073.diff (3.1 KB) - added by koenb 3 years ago.
patch with test for 12073

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by kmtracey

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Fixed formatting. Please use WikiFormatting and the preview button.

comment:2 Changed 4 years ago by russellm

  • milestone set to 1.2
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 4 years ago by ubernostrum

  • milestone 1.2 deleted

1.2 is feature-frozen, moving this feature request off the milestone.

comment:4 Changed 3 years ago by anonymous

attrs.update() is maybe too simple - that still wouldn't allow to change (or just add) a CSS class or change the size

comment:5 Changed 3 years ago by julien

  • Easy pickings unset
  • Has patch set
  • Needs tests set
  • Patch needs improvement set
  • Severity set to Normal
  • Type set to New feature

Changed 3 years ago by koenb

patch with test for 12073

comment:6 Changed 3 years ago by koenb

  • Easy pickings set
  • Needs tests unset
  • Patch needs improvement unset
  • UI/UX unset
  • Version changed from 1.0 to SVN

The attached patch allows passing attrs into AdminDateWidget and AdminTimeWidget. Added a test too.

comment:7 Changed 3 years ago by julien

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

In [17125]:

Fixed #12073 -- Made AdminDateWidget and AdminTimeWidget consider user-supplied attrs. Thanks to elliss for the report and to koenb for the patch.

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.