Open marcoshoya opened 9 years ago
You can override those options by defining "minDate" and "maxDate" in the 'configs' when creating your field :
class MyFormType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('my_date', 'genemu_jquerydate', [
'widget' => 'single_text',
'label' => 'publisher.poll.closing_date',
'format' => $format,
'configs' => [
'minDate' => [MY_MIN_DATE],
'maxDate' => [MY_MAX_DATE],
],
'required' => false,
]);
}
}
Yes - You can overwrite minDate and maxDate, but only by using numeric offset like -20, or string of periods and units like "+2M +4D", but not by passing a date, since in the template there is this thing:
$.datepicker.regional['{{ culture }}'] ,{{ configs|json_encode|raw }});
It means, that if You set it like bellow it won't work:
class MyFormType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('my_date', 'genemu_jquerydate', [
'widget' => 'single_text',
'label' => 'publisher.poll.closing_date',
'format' => $format,
'configs' => [
'minDate' => new \DateTime(),
'maxDate' => "any string representing valid date",
],
'required' => false,
]);
}
}
I think that json_encode twig filter (which is actually regular PHP json_decode function) should be replaced with a custom one which will check if minDate/maxDate are date object, and then it'll create javascript Date() from it...
I've tried to use jquery datetime plugin on my application and I could not configure the initial and final date from calendar that was showing.
After spend a little time looking for solution, I've opened widget template and found it:
And the template:
So, this is my point: why
minDate: new Date({{ min_year }}, 0, 1)
andmaxDate: new Date({{ max_year }}, 11, 31)
are hardcode?