Git Product home page Git Product logo

Comments (4)

stephenmcd avatar stephenmcd commented on June 25, 2024

This already exists as FORMS_BUILDER_USE_HTML5 - please consult the readme.

from django-forms-builder.

sindresorhus avatar sindresorhus commented on June 25, 2024

@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. ?

from django-forms-builder.

stephenmcd avatar stephenmcd commented on June 25, 2024

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.

from django-forms-builder.

sindresorhus avatar sindresorhus commented on June 25, 2024

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.

from django-forms-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.