contao-components/datepicker
Datepicker widget for Contao components: a lightweight, reusable date selection UI you can drop into Contao projects. Provides an interactive calendar input to pick dates consistently across forms and back-office interfaces.
Installation
composer require contao-components/datepicker
Ensure contao-components/datepicker is added to require in composer.json.
Basic Usage in Blade
Include the CSS/JS assets in your layout file (e.g., resources/views/layouts/app.blade.php):
<link href="{{ asset('vendor/contao-components/datepicker/css/datepicker.css') }}" rel="stylesheet">
<script src="{{ asset('vendor/contao-components/datepicker/js/datepicker.js') }}"></script>
First Implementation Add a date input field in a Blade view:
<input type="text" id="event-date" name="event_date" class="datepicker">
Initialize the datepicker via JavaScript:
document.addEventListener('DOMContentLoaded', function() {
new Datepicker(document.getElementById('event-date'));
});
Or use jQuery (if included):
$(document).ready(function() {
$('.datepicker').datepicker();
});
Laravel Form Integration Use the package with Laravel Collective or native forms:
{{ Form::text('event_date', null, ['class' => 'datepicker']) }}
Or:
<input type="text" name="event_date" class="datepicker" value="{{ old('event_date') }}">
Dynamic Initialization Initialize datepickers for multiple fields dynamically:
document.querySelectorAll('.datepicker').forEach(input => {
new Datepicker(input);
});
Form Request Validation Validate dates in Laravel Form Requests:
public function rules()
{
return [
'event_date' => 'required|date_format:Y-m-d',
];
}
Localization Set locale via JavaScript:
new Datepicker(document.getElementById('event-date'), {
locale: 'de-DE',
});
Or configure globally (if supported):
Datepicker.setDefaultOptions({ locale: 'fr-FR' });
Integration with Laravel Livewire Use Alpine.js or Livewire events to trigger initialization:
document.addEventListener('livewire:init', () => {
new Datepicker(document.getElementById('livewire-date'));
});
Custom Date Ranges Restrict date selection in forms:
new Datepicker(document.getElementById('start-date'), {
minDate: new Date(),
maxDate: new Date('2025-12-31'),
});
AJAX-Driven Forms Use the datepicker with AJAX submissions:
$('.datepicker-form').on('submit', function(e) {
e.preventDefault();
const date = $('.datepicker').val();
// Send date via AJAX
});
Laravel Nova Customization Extend Nova fields (if applicable):
use Contao\Datepicker\Datepicker;
public function fields(Request $request)
{
return [
Text::make('Event Date')
->onlyOnDetail()
->asHtml()
->script(<<<JS
new Datepicker(document.getElementById('field_event_date'));
JS),
];
}
Asset Paths
vendor/contao-components/datepicker/ exists. If using a custom install path, update asset paths in Blade.composer.json and run composer dump-autoload.Conflicting Libraries
.noConflict() or prefer vanilla JS initialization.Locale Mismatches
en-US vs. en-GB).Server-Side Validation
required|date in Form Requests.Caching Issues
php artisan cache:clear) or use versioned assets.Mobile Responsiveness
<input type="date">).Console Errors Check browser console for missing files or JS errors. Common issues:
Uncaught ReferenceError: Datepicker is not defined → Asset not loaded.Failed to load resource → Incorrect path in Blade.Inspect Initialization Verify the datepicker is initialized:
console.log(document.getElementById('event-date').classList.contains('datepicker'));
Disable for Testing
Temporarily remove the datepicker class to isolate issues:
<input type="text" id="event-date" name="event_date" class="{{ false ? 'datepicker' : '' }}">
Custom Themes Override CSS by extending the default stylesheet:
/* resources/css/app.css */
.datepicker-custom {
background: #f0f0f0;
}
Then add a class to the input:
<input type="text" class="datepicker datepicker-custom">
Event Listeners Attach callbacks for date selection:
new Datepicker(document.getElementById('event-date'), {
onSelect: function(date) {
console.log('Selected:', date);
// Trigger Laravel event or AJAX call
}
});
Laravel Mix/Webpack Process assets for production:
// webpack.mix.js
mix.copy('node_modules/contao-components/datepicker/css', 'public/vendor/datepicker/css');
mix.copy('node_modules/contao-components/datepicker/js', 'public/vendor/datepicker/js');
Server-Side Date Handling Parse dates in Laravel:
$date = \Carbon\Carbon::parse($request->input('event_date'));
Or use Carbon’s createFromFormat for custom formats.
Accessibility Ensure ARIA attributes are present:
<input type="text" aria-label="Event date" class="datepicker">
Or extend the package’s JS to add ARIA roles dynamically.
How can I help you explore Laravel packages today?