diff --git a/datetimewidget/static/js/django-datetime-widget.js b/datetimewidget/static/js/django-datetime-widget.js new file mode 100644 index 0000000..afa61be --- /dev/null +++ b/datetimewidget/static/js/django-datetime-widget.js @@ -0,0 +1,6 @@ +$(document).ready(function() { + $("div.ddw-requirable-readonly>input").on('keydown paste', function (e) { + e.preventDefault(); + }); +}); + diff --git a/datetimewidget/widgets.py b/datetimewidget/widgets.py index b159c31..57aca3b 100644 --- a/datetimewidget/widgets.py +++ b/datetimewidget/widgets.py @@ -100,7 +100,7 @@ def get_supported_language(language_country_code): BOOTSTRAP_INPUT_TEMPLATE = { 2: """ -
+
%(rendered_widget)s %(clear_button)s @@ -110,7 +110,7 @@ def get_supported_language(language_country_code): """, 3: """ -
+
%(rendered_widget)s %(clear_button)s @@ -221,6 +221,12 @@ def __init__(self, attrs=None, options=None, usel10n=None, bootstrap_version=Non def render(self, name, value, attrs=None): final_attrs = self.build_attrs(attrs) + + ddw_classes = [] + if 'required' in final_attrs and 'readonly' in final_attrs: + final_attrs.pop('readonly') + ddw_classes.append('ddw-requirable-readonly') + rendered_widget = super(PickerWidgetMixin, self).render(name, value, final_attrs) #if not set, autoclose have to be true. @@ -245,13 +251,14 @@ def render(self, name, value, attrs=None): rendered_widget=rendered_widget, clear_button=CLEAR_BTN_TEMPLATE[self.bootstrap_version] if clearBtn else "", glyphicon=self.glyphicon, - options=js_options + options=js_options, + ddw_classes=' '.join(ddw_classes), ) ) def _media(self): - js = ["js/bootstrap-datetimepicker.js"] + js = ["js/bootstrap-datetimepicker.js", "js/django-datetime-widget.js"] language = self.options.get('language', 'en') if language != 'en':