Skip to content

Instantly share code, notes, and snippets.

@stof
Created March 5, 2012 22:11
Show Gist options
  • Save stof/1981504 to your computer and use it in GitHub Desktop.
Save stof/1981504 to your computer and use it in GitHub Desktop.
Autocompleter type for Symfony2 forms
jQuery(function($) {
// initialise the "Select date" link
$.datepicker.setDefaults($.datepicker.regional[ "fr" ]);
// associate the link with a date picker
$('.tolk_date_picker').each(function(){
var self = $(this);
self.datepicker({
dateFormat: 'dd/mm/y',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
firstDay: 1,
monthNamesShort: ['janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
showOn: "button",
buttonImageOnly: true,
buttonImage: self.attr('data-datepicker-icon')
});
});
});
<?php
namespace Tolkiendil\AssoBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
class DatePickerType extends AbstractType
{
public function getDefaultOptions(array $options)
{
return array(
'widget' => 'single_text',
'format' => 'dd/MM/yy',
'attr' => array(
'autocomplete' => 'off',
'class' => 'tolk_date_picker',
),
);
}
public function getParent(array $options)
{
return 'date';
}
public function getName()
{
return 'tolkiendil_date_picker';
}
}
@cordoval
Copy link

@stof can your recommend the best looking timepicker with bootstrap?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment