From 3d8bf3ec9b9e6da6b4c438c9c2bc872002e15f76 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 25 Jun 2023 06:24:08 +0200 Subject: [PATCH] Fix #7683 --- app/Http/Controllers/Json/RecurrenceController.php | 10 +++++++--- public/v1/js/ff/recurring/create.js | 4 ++-- resources/views/form/date.twig | 2 -- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Json/RecurrenceController.php b/app/Http/Controllers/Json/RecurrenceController.php index 25de916d5a..97d84bd088 100644 --- a/app/Http/Controllers/Json/RecurrenceController.php +++ b/app/Http/Controllers/Json/RecurrenceController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; use Carbon\Carbon; +use Carbon\Exceptions\InvalidFormatException; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\RecurrenceRepetition; @@ -150,10 +151,13 @@ class RecurrenceController extends Controller */ public function suggest(Request $request): JsonResponse { - $request->validate(['date' => ['required', 'date'],]); - $string = $request->get('date') ?? date('Y-m-d'); + $string = '' === (string)$request->get('date') ? date('Y-m-d') : (string)$request->get('date'); $today = today(config('app.timezone'))->startOfDay(); - $date = Carbon::createFromFormat('Y-m-d', $string)->startOfDay(); + try { + $date = Carbon::createFromFormat('Y-m-d', $string, config('app.timezone'))->startOfDay(); + } catch(InvalidFormatException $e) { + $date = Carbon::today(config('app.timezone')); + } $preSelected = (string)$request->get('pre_select'); $locale = app('steam')->getLocale(); diff --git a/public/v1/js/ff/recurring/create.js b/public/v1/js/ff/recurring/create.js index a0e98757f6..70ab44a212 100644 --- a/public/v1/js/ff/recurring/create.js +++ b/public/v1/js/ff/recurring/create.js @@ -116,9 +116,9 @@ function respondToFirstDateChange() { preSelected = select.val(); } - $.getJSON(suggestUrl, {date: date,pre_select: preSelected}).fail(function () { + $.getJSON(suggestUrl, {date: date,pre_select: preSelected, past: 'true'}).fail(function () { console.error('Could not load repetition suggestions'); - alert('Could not load repetition suggestions'); + alert('Could not load repetition suggestions. Please enter a valid date.'); }).done(parseRepetitionSuggestions); } diff --git a/resources/views/form/date.twig b/resources/views/form/date.twig index 6fab186db2..68a14ecd64 100644 --- a/resources/views/form/date.twig +++ b/resources/views/form/date.twig @@ -1,5 +1,4 @@
- {{ dump(options) }} @@ -8,7 +7,6 @@
- {{ Html.input('date', name, value).id(options.id).class('form-control').attribute('autocomplete','off').attribute('spellcheck','false') .attribute('min', options.min) }}