Skip to content

Commit

Permalink
Improve consistency of reset value handling for date
Browse files Browse the repository at this point in the history
* Consistent implementation re: `datetime`
* Consistent reset using `DATE_INPUT_FORMAT`, i.e.
  - Works whether `USE_L10N` setting is active or not
  • Loading branch information
myii committed May 7, 2018
1 parent 887ee92 commit c9916c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions constance/static/admin/js/constance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

if (fieldType === 'checkbox') {
field.prop('checked', this.dataset.default === 'true');
} else if (fieldType === 'date') {
var defaultDate = new Date(this.dataset.default * 1000);
$('#' + this.dataset.fieldId).val(defaultDate.strftime(get_format('DATE_INPUT_FORMATS')[0]));}
} else if (fieldType === 'datetime') {
var defaultDate = new Date(this.dataset.default * 1000);
$('#' + this.dataset.fieldId + '_0').val(defaultDate.strftime(get_format('DATE_INPUT_FORMATS')[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
data-field-id="{{ item.form_field.auto_id }}"
data-field-type="{% spaceless %}
{% if item.is_checkbox %}checkbox
{% elif item.is_date %}date
{% elif item.is_datetime %}datetime
{% endif %}
{% endspaceless %}"
data-default="{% spaceless %}
{% if item.is_checkbox %}{% if item.raw_default %} true {% else %} false {% endif %}
{% elif item.is_date %}{{ item.raw_default|date:"U" }}
{% elif item.is_datetime %}{{ item.raw_default|date:"U" }}
{% elif item.is_date %}{{ item.raw_default.isoformat }}
{% else %}{{ item.default }}
{% endif %}
{% endspaceless %}">{% trans "Reset to default" %}</a>
Expand Down

0 comments on commit c9916c7

Please sign in to comment.