#33100: Add a DateInput widget that provides a date picker via the HTML <input
style="date"> element
-----------------------------+--------------------------------------
     Reporter:  dvg          |                    Owner:  nobody
         Type:  New feature  |                   Status:  closed
    Component:  Forms        |                  Version:  3.2
     Severity:  Normal       |               Resolution:  duplicate
     Keywords:               |             Triage Stage:  Unreviewed
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+--------------------------------------

Comment (by Steven Mapes):

 It should be noted that just changing the type attribute is **not** all
 you need to do in order to use the date and time  inputs correctly within
 Django. Whilst doing that will render the HTML input it will not pickup
 the initial values correctly as you need to format them into the right
 input format, normally by using isoformat() on either the initial or
 instance value depending on whether you are using a standard form or model
 form.

 The "datetime-local" input will work okay without any other changes.

 For the sake of anyone coming back to this ticket in the future here's one
 way of subclassing the DateInput and TimeInput widgets with the updated
 render method that will mean you can then use these as you would standard
 widgets and won't hit the issues described above

 {{{
 class DateInputPicker(DateInput):
     input_type = "date"

     def render(self, name, value, attrs=None, renderer=None):
         """Render the widget as an HTML string."""
         value = value.isoformat() if value and isinstance(value, date)
 else value
         context = self.get_context(name, value, attrs)
         return self._render(self.template_name, context, renderer)


 class TimeInputPicker(TimeInput):
     input_type = "time"

     def render(self, name, value, attrs=None, renderer=None):
         """Render the widget as an HTML string."""
         value = value.isoformat() if value and isinstance(value, date)
 else value
         context = self.get_context(name, value, attrs)
         return self._render(self.template_name, context, renderer)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33100#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701836647d09a-4f21235a-f7af-4918-87a6-e152de6e24c5-000000%40eu-central-1.amazonses.com.

Reply via email to