stephenmcd / django-forms-builder

Let users build forms in Django admin
BSD 2-Clause "Simplified" License
691 stars 281 forks source link

Option to use the Django date and datetime widgets #19

Closed sindresorhus closed 13 years ago

sindresorhus commented 13 years ago

The current browser implementation of date and datetime is currently buggy at best or non existant.

Give us an option to use the Django widgets instead.

FORMS_BUILDER_USE_BUILTIN_WIDGETS

stephenmcd commented 13 years ago

This already exists as FORMS_BUILDER_USE_HTML5 - please consult the readme.

sindresorhus commented 13 years ago

@stephenmcd I've read the README several times and tried setting the FORMS_BUILDER_USE_HTML5 to both False and True, but I can't seem to get the Django date and datetime widgets. ?

stephenmcd commented 13 years ago

Ok a little background on this - the correct Django date and datetime widgets are certainly being used when FORMS_BUILDER_USE_HTML5 is set to False. What you will find however is that the default widgets for these are simply text inputs - take a look in the Django source at django.forms.widgets.DateInput and django.forms.widgets.TimeInput.

Now there is a widget in Django that isn't the default for the DateField but is slightly better than the default. That widget is django.forms.extras.SelectDateWidget which gives you 3 select menus for day month and year. Now if you take a look in forms_build.forms.fields, you'll see a structure that defines which custom widgets to use when FORMS_BUILDER_USE_HTML5 is set to False. Here you'll find SelectDateWidget defined for date fields, but nothing defined for datetime fields as from what I know there isn't a better non-default widget for date time fields in Django as there is with date fields.

You may be comparing this to the widgets used in Django's admin interface - I haven't gone through the code in django.contrib.admin to confirm this, but I suspect these are implemented with Javascript on top of some hidden input fields, and aren't implemented by actual widget classes.

So in conclusion, with FORMS_BUILDER_USE_HTML5 set to False you should get a more usable widget for date fields, and datetime fields will still contain a text input, all based on what's available in Django.

If you'd like to go ahead and implement some enhanced widget classes for these without any Javascript required, I'd be happy to merge them in as I agree that the widgets that Django provides certainly leave room for improvement.

sindresorhus commented 13 years ago

You're probably right. Too be honest, I haven't really looked much at the Django source code.

The reason I brought this up was that I was expecting the Admin widgets of date and datetime (with the JS stuff) to show up when I set FORMS_BUILDER_USE_HTML5 to false. After you're explanation it's clear that that isn't something you get out of the box.

It's possible to get the admin data/datetime JS widgets on your own forms: http://stackoverflow.com/questions/38601/using-django-time-date-widgets-in-custom-form

Would be useful if this could be built-in.