heimrichhannot / contao-flatpickr-bundle
A bundle to provide flatpickr support for contao.
Installs: 1 435
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Type:contao-bundle
Requires
- php: ^7.4 || ^8.0
- contao/core-bundle: ^4.9
- heimrichhannot/contao-encore-contracts: ^1.0.2
- heimrichhannot/contao-twig-support-bundle: ^0.2.16 || ^1.0
- heimrichhannot/contao-utils-bundle: ^2.225
- symfony/event-dispatcher-contracts: ^1.0 || ^2.0 || ^3.0
- dev-master
- 2.9.4
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.1
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.1.0
- 1.0.1
- 1.0.0
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/date_range
- dev-hotfix-input-filter-element
- dev-added-support-for-non-dca-fields
This package is auto-updated.
Last update: 2024-11-21 14:48:13 UTC
README
A bundle to provide frontend date- and timepicker using flatpickr.js.
Features
- show date- or timepicker in frontend forms
- dynamic language file loading using webpack dynamic import
- integrations:
- Contao form generator
- Filter Bundle
- supports Contao Encore Bundle
- supports Twig Templates Bundle
Usage
Install
Install with composer or contao manager and update the database afterwards
composer require heimrichhannot/contao-flatpickr-bundle
Form generator
Create a text field with input validation date, time or date and time and check 'Activate flatpickr'
Filter bundle
Create a filter element of type date, datetime, time or text and check 'Activate flatpickr'. You can also activate flatpickr and pass additional options from dca. See chapter dca configuration for more information. Flatpickr bundle checks the corresponding field dca configuration for filter elements.
DCA / Other frontend forms
Other frontend form systems may work (like formhybrid), if the form widgets are processed by the getAttributesFromDca hook. You need to activate flatpickr in your dca field configuration and activate flatpickr on page level (layout section). The configuration is inherited but can be overridden.
To actived flatpickr for a dca field, set field.eval.flatpickr.active
to true
.
$GLOBALS['TL_DCA']['tl_content']['fields']['date']['eval']['flatpickr']['active'] = true;
You can customize the picker type with rgxp
eval option and pass additional flatpickr configuration:
$GLOBALS['TL_DCA']['tl_content']['fields']['date'] = [ 'eval' => [ 'rgxp' => 'datim' # one of 'date', 'time' or 'datim' 'flatpickr' => [ 'active' => true, 'options' => [], // Pass addtional flatpickr option, see configuration chapter 'plugins' => [], // Use and configure flatpickr plugins, see configuration chapter ], ] ];
Configuration
If flatpickr is activated for a field, it already works "out-of-the-box". Sometime additional customization are needed.
Flatpickr picker type
Three picker types are supported: date, time and datetime.
The types are automatically selected by setting the rgxp
value to one of 'date', 'time' or 'datim'
$field['eval']['rgxp'] = 'time'
Custom configuration
The most config options from flatpickr should work with this bundle.
These options can be set from:
- DCA (works for filter bundle and other frontend forms): Add the configuration to
$field['eval']['flatpickr']['options']
- php event (work with all types): See developers chapter
- javascript event (work with all type): see developers chapter
Typical configuration options:
Following additional configuration are available from this bundle:
Plugins
Flatpickr can be extended with plugins. Plugins supported by this bundle can by activated and configured from $field['eval']['flatpickr']['plugins']
.
monthSelectPlugin
monthSelectPlugin shows a month-only calendar view. Additional to the default configuration options of the plugin
there is an addition disabledMonths
option.
Example:
$GLOBALS['TL_DCA']['tl_content']['fields']['date']['eval']['flatpickr']['plugins']['monthSelectPlugin'] = [ 'shorthand' => true, 'dateFormat' => "M Y", 'disabledMonths' => [2021 => [0,3,6]] ];
rangePlugin
rangePlugin add a range selection using two inputs. It can be enabled in form generator or from dca:
$GLOBALS['TL_DCA']['tl_content']['fields']['startDate']['eval']['flatpickr']['plugins']['rangePlugin'] = [ 'input' => '#stopDate', ];
Developers
Events
JavaScript events
Update from version 1.x to 2.x
- add
flatpickr => [ active => true ]
to the eval array of the dca configuration - move the configuration in dca from
eval
toeval => [ flatpickr => [ options => [ option => value ] ] ]