digitalframe/beta-datetimepicker-bundle
Installation:
composer require digitalframe/datetimepicker-bundle:dev-master
Update AppKernel.php to include the bundle:
new Digitalframe\DatetimepickerBundle\DigitalframeDatetimepickerBundle(),
Configure:
Add minimal config in config.yml:
digitalframe_datetimepicker: ~
Assets: Run:
php app/console assets:install web/
Add the field type to a form:
// src/AppBundle/Form/YourFormType.php
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('eventDate', 'df_datetime');
}
Include the bundle’s JS/CSS in your template:
{{ form_stylesheets(form) }}
{{ form_javascripts(form) }}
Basic Integration:
Use 'df_datetime' as a field type in forms. Defaults to English locale and MM/DD/YYYY HH:mm format.
Localized Picker: Override defaults per field:
$builder->add('birthday', 'df_datetime', [
'locale' => 'fr',
'format' => 'DD/MM/YYYY'
]);
Dynamic Configuration:
Pass options via form options or entity properties (if using DataTransformer or custom logic).
Reusing in Templates: Render the field with Twig:
{{ form_row(form.eventDate) }}
symfony/form (this bundle targets Symfony 2).webpack or encore for modern builds if assets are bundled.DigitalframeDatetimepickerBundle::datetime_widget.html.twig for UI tweaks.Asset Conflicts:
datetimepicker.js or bootstrap-datetimepicker.css exists in your project.assets:install:
php app/console cache:clear
Locale Mismatch:
'es') matches a loaded moment.js locale.Symfony 2 Legacy:
FormBuilder (not FormBuilderInterface), which may cause issues in newer Symfony versions.Missing Dependencies:
bootstrap and jquery (check form_stylesheets/form_javascripts output).moment.js or datetimepicker initialization errors (e.g., missing locales).<head>).'df_datetime').Custom Options:
Extend the bundle’s DatetimeType to add new options:
// src/AppBundle/Form/Extension/DatetimeExtension.php
use Symfony\Component\Form\AbstractTypeExtension;
class DatetimeExtension extends AbstractTypeExtension {
public function getExtendedType() {
return 'df_datetime';
}
public function getDefaultOptions() {
return ['new_option' => false];
}
}
Template Overrides:
Copy vendor/digitalframe/datetimepicker-bundle/Resources/views/Form/ to app/Resources/DigitalframeDatetimepickerBundle/views/Form/ for custom templates.
Event Listeners:
Attach logic to form events (e.g., PRE_SET_DATA) to dynamically set options:
$form->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$event->getForm()->add('customField', 'df_datetime', ['format' => 'YYYY']);
});
How can I help you explore Laravel packages today?