Skip to content

Commit

Permalink
Fix datepicker for inline admin (#263)
Browse files Browse the repository at this point in the history
fix #255
  • Loading branch information
mobinghoveoud authored Oct 22, 2024
1 parent c23cd27 commit be8d97d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
6 changes: 5 additions & 1 deletion django_jalali/static/admin/css/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
img.ui-datepicker-trigger {
height: 15px;
height: 16px;
width: 16px;
margin-top: auto;
margin-bottom: auto;
padding: 5px;
}
35 changes: 28 additions & 7 deletions django_jalali/static/admin/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
$(function () {
function activateDatepicker() {
$('.vjDateField').each(function() {
var inputId = $(this).attr('id') || '';
if (inputId.includes('__prefix__')) {
return;
}

$(this).datepicker({
dateFormat: "yy-mm-dd",
changeMonth: true,
changeYear: true,
showOn: "both",
buttonImage: "/static/admin/jquery.ui.datepicker.jalali/themes/base/images/icon-calendar.svg",
buttonImageOnly: true,
isRTL: false,
buttonText: "یک تاریخ انتخاب کنید",
});
});
}

if (!$.datepicker){$ = django.jQuery;}
$('.vjDateField').datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
showOn: 'button',
buttonImage: '/static/admin/jquery.ui.datepicker.jalali/themes/base/images/icon-calendar.svg',
buttonImageOnly: true
activateDatepicker();

$(document).on('formset:added', function(event, $row, formsetName) {
activateDatepicker();
});

$(document).on('formset:removed', function(event, $row, formsetName) {
activateDatepicker();
});
});

0 comments on commit be8d97d

Please sign in to comment.