This commit is contained in:
James Cole 2023-06-25 06:24:08 +02:00
parent 55e4479454
commit 3d8bf3ec9b
3 changed files with 9 additions and 7 deletions

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json; namespace FireflyIII\Http\Controllers\Json;
use Carbon\Carbon; use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\RecurrenceRepetition; use FireflyIII\Models\RecurrenceRepetition;
@ -150,10 +151,13 @@ class RecurrenceController extends Controller
*/ */
public function suggest(Request $request): JsonResponse public function suggest(Request $request): JsonResponse
{ {
$request->validate(['date' => ['required', 'date'],]); $string = '' === (string)$request->get('date') ? date('Y-m-d') : (string)$request->get('date');
$string = $request->get('date') ?? date('Y-m-d');
$today = today(config('app.timezone'))->startOfDay(); $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'); $preSelected = (string)$request->get('pre_select');
$locale = app('steam')->getLocale(); $locale = app('steam')->getLocale();

View File

@ -116,9 +116,9 @@ function respondToFirstDateChange() {
preSelected = select.val(); 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'); 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); }).done(parseRepetitionSuggestions);
} }

View File

@ -1,5 +1,4 @@
<div class="{{ classes }}" id="{{ name }}_holder"> <div class="{{ classes }}" id="{{ name }}_holder">
{{ dump(options) }}
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label> <label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
@ -8,7 +7,6 @@
<div class="input-group-addon"> <div class="input-group-addon">
<span class="fa fa-calendar"></span> <span class="fa fa-calendar"></span>
</div> </div>
{{ Html.input('date', name, value).id(options.id).class('form-control').attribute('autocomplete','off').attribute('spellcheck','false') {{ Html.input('date', name, value).id(options.id).class('form-control').attribute('autocomplete','off').attribute('spellcheck','false')
.attribute('min', options.min) .attribute('min', options.min)
}} }}