Date/Time Picker Fields
Last updated
Last updated
We have three field types related to date and/or time:
To make the input more convenient, we use a jQuery library called Datetimepicker, to power all of them. Here's how it looks visually.
Date Picker:
Date/Time Picker:
Time Picker:
To make those pickers work, we're loading a Bootstrap Date/Time Picker library directly from CDN:
Notice: that library is now renamed to "Tempus Dominus" and is in process of creating a new version, but we're using older and stable v4.17.
We also load the Moment.js library from CDN, which helps with time manipulation in JavaScript:
Then, in the file public/js/main.js we have this jQuery code to enable pickers:
So, in Blade files, every picker input field has its class, like <input class="date" />, or <input class="datetime" />, or <input class="timepicker" />.
The most typical customization is changing the date/time formats. I will show you two examples.
First, you can configure your date format in the panel settings:
After downloading the code, you can also make the changes. Besides the date formats you can see in the previous code sample (like, "format: 'MM/DD/YYYY HH:mm:ss'"), we also have the configuration on the back-end of Laravel, to convert the dates to/from the database.
So, here's config/panel.php:
So, if you want to change the formats, you need to change them both in JavaScript, and in Laravel.
Keep in mind that JavaScript formats are powered by Moment.js, and Laravel formats are powered by the PHP date() function.
To use hours like "3pm" instead of "15", you need to make these changes:
config/panel.php:
public/js/main.js:
If you want to skip seconds in datetime/time picker, here are the changes to make:
config/panel.php:
public/js/main.js: