Open Hiieu opened 9 years ago
@Hiieu Try to change "datetime" by the name of one of your models.
Aaah can't do that. MyModel have to have DateField()
I think that what @fercreek meant was change 'datetime' to 'start_date' or 'end_date'
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 }}
widgets = { 'start_date': DateWidget(attrs={'id': "start_date"}, usel10n=True, bootstrap_version=3) }
@fercreek What is the name of the field in your model you want to use this widget with?
@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.
Same issue. Amplifying data: I receive this message in the JS console: 'TypeError: $(...).datetimepicker is not a function'
@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.)
Thanks; will check that out when I'm back home in a month.
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.
I had this issue as well, but I was able to fix it. The things I checked (and forgot to do):
<script>
to the top of your template{{ form_name.media }}
in the <head>
of your templatedatetimewidget
in your INSTALLED_APPS
(i forgot this)
I have all requirements. So I think something is wrong with my model or form