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

Datepicker is not showing #75

Open
Hiieu opened this issue Jun 16, 2015 · 12 comments
Open

Datepicker is not showing #75

Hiieu opened this issue Jun 16, 2015 · 12 comments

Comments

@Hiieu
Copy link

Hiieu commented Jun 16, 2015

I have all requirements. So I think something is wrong with my model or form

#models.py
class MyModel(models.Model):
    number = models.IntegerField(max_length=20, unique=True)
    start_date = models.DateField(null=True, blank=True)
    end_date = models.DateField(null=True, blank=True)

    def __str__(self):
        return '%s' % self.first_name
#forms.py
class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel
        widgets = {
            'datetime': DateTimeWidget(attrs={'id': "yourdatetimeid"})
        }
@fercreek
Copy link

@Hiieu Try to change "datetime" by the name of one of your models.

@Hiieu
Copy link
Author

Hiieu commented Jun 23, 2015

Aaah can't do that. MyModel have to have DateField()

@HadrienMP
Copy link

I think that what @fercreek meant was change 'datetime' to 'start_date' or 'end_date'

@Hiieu
Copy link
Author

Hiieu commented Jun 25, 2015

Unfortunately it is still not working

    widgets = {
        'start_date': DateWidget(attrs={'id': "yourdatetimeid"})
    }

I got bootstrap.js and bootsrap.min.css and jquery 1.8.3 and {{ form.media }}

@fercreek
Copy link

widgets = {
'start_date': DateWidget(attrs={'id': "start_date"}, usel10n=True, bootstrap_version=3)
}

@n3storm
Copy link

n3storm commented Jul 10, 2015

@fercreek What is the name of the field in your model you want to use this widget with?

@ollytheninja
Copy link

@Hiieu does it matter that you are using a DateTimeWidget with a DateField not a DateTimeField?

I do it like so:
"event_start": DateTimeWidget(bootstrap_version=3)
If you aren't changing the IDs of the form fields you shouldn't have to specify them manually.

@David-OConnor
Copy link

Same issue. Amplifying data: I receive this message in the JS console: 'TypeError: $(...).datetimepicker is not a function'

@ssokolow
Copy link

ssokolow commented May 24, 2016

@David-OConnor Check what HTML is actually getting generated by {{ form.media }} to narrow down the location of the problem.

In my case, I'd accidentally typo'd a field name, which caused Django to omit the CSS and JS associated with DateTimeWidget since no field on the page used it.

If it IS working, make sure you're NOT doing the perceptual optimization of loading your JavaScript in the page footer like the Bootstrap people tell you to do.

This widget injects inline JavaScript into the page body, which means {{ form.media }} must be in the page header... and {{ form.media }} must come after jQuery, which means you can't load that in the page footer either.

(The long-term solution is to rework the JS so configuration is done using data- attributes and no inline scripting is injected. That'd also have the benefit of allowing a Content Security Policy which prevents XSS by instructing the user's browser to ignore JavaScript within HTML files.)

@David-OConnor
Copy link

Thanks; will check that out when I'm back home in a month.

@joej
Copy link

joej commented Oct 29, 2017

I'm thinking ... the "$(#.......)" javascript runs BEFORE you have loaded jquery.

If you load jquery in head, then it shouldn't be a problem. If you load it in the bottom of the doc, then you might see this err.

@treyd
Copy link

treyd commented Nov 13, 2017

I had this issue as well, but I was able to fix it. The things I checked (and forgot to do):

  1. Move jQuery <script> to the top of your template
  2. Make sure you are including {{ form_name.media }} in the <head> of your template
  3. Make sure you've got datetimewidget in your INSTALLED_APPS (i forgot this)

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

9 participants