marshmallow/nova-date-range-field

A Laravel Nova field.

v1.0.6 2023-12-12 11:35 UTC

This package is auto-updated.

Last update: 2024-11-12 13:33:38 UTC


README

Nova field for a Date Range Picker.

Install

Run this command in your nova project: composer require marshmallow/nova-date-range-field

How to use

Use the (dependend) DateRange Field class and define the name of the (from & till) fields and the label. If no fields are set the string value will be stored in the corresponding database column of the attribute.

    use Marshmallow\NovaDateRangeField\DateRange;

    public function fields(Request $request)
    {
        return [
             DateRange::make(__('Access Date'), ['from', 'till'])
                // OR
             DateRange::make(__('Access Date'))
                ->fields('from', 'till'),
        ];
    }

Aditional options from flatpickr can be used by adding them in the options array. These will overwrite the default options.

     DateRange::make(__('Date range'))
        ->fields('from', 'till')
        ->options([
            'defaultHour' => 0,
            'defaultMinute' => 0,
        ]),

Other field options (with their default values) are:

    ->modeType('range')
    ->range() // Default mode
    ->single() // default is disabled
    ->twelveHourTime() // default is disabled
    ->enableSeconds() // default is disabled
    ->separator('-')
    ->firstDayOfWeek(1)
    ->enableTime() // default is disabled
    ->dateFormat('Y-m-d')
    ->placeholder('date range')
    ->saveAsJSON() // default is disabled