I have a problem with this datepicker : http://bootstrap-datepicker.readthedocs.org/en/stable/index.html
I work with symfony framework, on last version.
I do all css/js file inclusion, i add a class on my field for js, and i use this configuration :
$('.datepick').datepicker({
language: "fr",
todayBtn: "linked",
keyboardNavigation: false,
forceParse: false,
calendarWeeks: true,
autoclose: true
});
So in regular step, i can select a date with my datepicker.
My problem is : when i don't select a date in form (optionnal field), the current date is always saved on field.
I just want to remove this behaviour : when no date is selected, no date is persist in entity. I don't have any idea for solve this.
Anyone have an idea ?
--
Thx for you help
my field in formtype is :
$builder->add('dateNaissance', 'birthday', array(
'label' => 'form.tiers.dateNaissance', 'translation_domain' => 'GBPCoreBundle', 'required' => false,
'widget' => 'single_text', 'format' => 'dd/MM/yyyy', 'input' => 'datetime', 'attr' => array('class' => 'datepick')
))
My view is :
{{ form_row(form.dateNaissance) }}
My entity is :
/**
* @var \Date
*
* @ORM\Column(name="dateNaissance", type="date", nullable=true)
* @Assert\Date(message="La date de naissance {{ value }} doit être un type {{ type }} valide.")
*/
private $dateNaissance;
and my consctructor is empty, i didn't set default value
My controller is very basic, i don't act on this field
First, verify your entity date field have nullable option like nullable=true
Then, If the problem persists, and you can't find any option to do this trick, you can use Javascript.
On document load, set the datepicker value with an empty string, using jQuery it's like :
$(document).ready(function(){
$('#dateField').val('');
});
Now, the default value is empty, and if value change (user choose a date), you save the date, else you save NULL
or ''
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.