From 8329ad0b5138983d632a940f5b47f5e49eda4767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E6=9C=A8=E8=A6=81?= Date: Wed, 19 Jul 2023 17:38:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=82=AB=E3=83=A9=E3=83=BC=E3=83=94?= =?UTF-8?q?=E3=83=83=E3=82=AB=E3=83=BC=E3=81=AE=E4=BF=AE=E6=AD=A3=E3=81=AE?= =?UTF-8?q?=E5=8F=96=E3=82=8A=E8=BE=BC=E3=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/function/businessLogicScript.js | 85 ++++++++++--------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/ecs/jskult-webapp/src/static/function/businessLogicScript.js b/ecs/jskult-webapp/src/static/function/businessLogicScript.js index d3cd0d96..768a0ac1 100644 --- a/ecs/jskult-webapp/src/static/function/businessLogicScript.js +++ b/ecs/jskult-webapp/src/static/function/businessLogicScript.js @@ -84,51 +84,54 @@ function selectDropDowList(id, selectedName){ function enableDatePicker() { // カレンダーの表示を日曜日始まりに変更 flatpickr.l10ns.ja.firstDayOfWeek = 0; - $('.date_picker').flatpickr( - { + + $(".date_picker").each(function(i, elem) { + const date_picker_name = elem.name; + + flatpickr(elem, { locale: 'ja', // 日本語カレンダー allowInput: true, // 入力可能にする - dateFormat: 'Y/m/d' // 日付のフォーマットを修正 - } - ) + dateFormat: "YYYY/MM/DD", // 日付のフォーマット + onChange(_dates, currentDateString, _picker, _data) { + }, + parseDate: function(strFormat, format) { + + // yyyyMMddの場合→yyyy/MM/dd + const datePatternMatches = strFormat.match(/^(\d{4})(\d{2})(\d{2})$/); + if (datePatternMatches){ + strFormat = `${datePatternMatches[1]}/${datePatternMatches[2]}/${datePatternMatches[3]}`; + } + + // yyyy/00/00~yyyy/00/00の場合→yyyy/01/01~yyyy/12/31 + // yyyy/MM/00~yyyy/MM/01の場合→yyyy/MM/01~yyyy/MM/末日 + // 開始日の場合 + if (date_picker_name.includes('from')){ + strFormat = strFormat.replace("/00/00", "/01/01"); + strFormat = strFormat.replace("/00", "/01"); + } + // 終了日の場合 + else if (date_picker_name.includes('to')){ + strFormat = strFormat.replace("/00/00", "/12/31"); + const date = new Date(strFormat.slice(0, 4), strFormat.slice(5, 7), 0).getDate(); + strFormat = strFormat.replace("/00", "/"+date.toString()); + } + return new Date(strFormat); + }, + formatDate: (date, format) => { + // 日付の整合性チェック、不正の場合は空表示 + if(isNaN(date.getDate())){ + return; + } + + // フォーマットを設定 + const formatted = flatpickr.formatDate(date,'Y/m/d'); + return formatted; + + } + }) + }); } -// 日付入力チェック -// 引数:チェックするテキストボックスNo -function autoModifyDate($this){ - // 日付フォーマットチェック - - if($this.value === "" || - (!$this.value.match(/^\d{4}\/\d{2}\/\d{2}$/) && !$this.value.match(/^\d{4}\d{2}\d{2}$/))) - { - $this.value = ""; - return; - } - - /** @type { string }*/ - let strFormat = $this.value;; - // yyyyMMddの場合→yyyy/MM/dd - const datePatternMatches = strFormat.match(/^(\d{4})(\d{2})(\d{2})$/); - if (datePatternMatches){ - strFormat = `${datePatternMatches[1]}/${datePatternMatches[2]}/${datePatternMatches[3]}`; - } - // yyyy/00/00~yyyy/00/00の場合→yyyy/01/01~yyyy/12/31 - // yyyy/MM/00~yyyy/MM/01の場合→yyyy/MM/01~yyyy/MM/末日 - // 開始日の場合 - if ($this.name.includes('from')){ - strFormat = strFormat.replace("00/00", "01/01"); - strFormat = strFormat.replace("00", "01"); - } - // 終了日の場合 - else if ($this.name.includes('to')){ - strFormat = strFormat.replace("00/00", "12/31"); - const date = new Date(strFormat.slice(0, 4), strFormat.slice(5, 7), 0).getDate(); - strFormat = strFormat.replace("00", date.toString()); - } - $this.value = strFormat; -} - - // 前のスペースを許さない入力チェック function checkSpaceForm($this) {