From be8d97de914d2c8fb2f15e3e09c76e794fc8d7d4 Mon Sep 17 00:00:00 2001 From: Mobin Ghoveoud Date: Tue, 22 Oct 2024 17:07:31 +0330 Subject: [PATCH] Fix datepicker for inline admin (#263) fix #255 --- django_jalali/static/admin/css/main.css | 6 ++++- django_jalali/static/admin/main.js | 35 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/django_jalali/static/admin/css/main.css b/django_jalali/static/admin/css/main.css index a7c64a2..2c9f959 100644 --- a/django_jalali/static/admin/css/main.css +++ b/django_jalali/static/admin/css/main.css @@ -1,3 +1,7 @@ img.ui-datepicker-trigger { - height: 15px; + height: 16px; + width: 16px; + margin-top: auto; + margin-bottom: auto; + padding: 5px; } diff --git a/django_jalali/static/admin/main.js b/django_jalali/static/admin/main.js index 6dd4074..8a5dded 100644 --- a/django_jalali/static/admin/main.js +++ b/django_jalali/static/admin/main.js @@ -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(); }); });