Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use the Django date and datetime widgets #19

Closed
sindresorhus opened this issue May 23, 2011 · 4 comments
Closed

Option to use the Django date and datetime widgets #19

sindresorhus opened this issue May 23, 2011 · 4 comments

Comments

@sindresorhus
Copy link
Contributor

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
Copy link
Owner

This already exists as FORMS_BUILDER_USE_HTML5 - please consult the readme.

@sindresorhus
Copy link
Contributor Author

@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
Copy link
Owner

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants