Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When using the #date_format to set the date format is not being used.
When using the #date_format to set the date format is not being used.
Comments
Comment #2
gordon CreditAttribution: gordon as a volunteer commentedThere seems to be a lot issues which stopped everything from working.
Comment #3
gordon CreditAttribution: gordon as a volunteer commentedDoing some more investigation on this I found that the date element \Drupal\views\Plugin\views\filter\Date::validateValidTime() only uses strtotime() to convert the string to a timestamp. So in using the date format of d/m/Y will not work as strtotime() will treat it as a m/d/Y format, so you need to use d-m-Y
Comment #4
grumpy74 CreditAttribution: grumpy74 commented@gordon
Thanks for pointing this. I have the same issue. How do you change the date picker format ?
Comment #5
ariane CreditAttribution: ariane commented@grumpy74
Maybe late but I wish I could help anyone else..
1) go to /admin/config/regional/translate
2) search the string mm/dd/yy
3) translate to dd-mm-yy
4) save and flush caches
5) try to search a date
It worked for me! Thanks @gordon !!
Comment #6
grumpy74 CreditAttribution: grumpy74 commented@ariane, thank you for the answer.
Comment #7
ericdsd CreditAttribution: ericdsd commentedThanks,
translating mm/dd/yy to dd-mm-yy
worked for me too
Note that translating to dd/mm/yy does not.
Comment #8
Radelson CreditAttribution: Radelson at WebstanZ commentedRerolled the patch for this issue against 5.0.0-beta1
I don't quite understand how the #date_format is supposed to be set without custom code but when it's there, it seems to work.
Comment #9
Neslee Canil PintoPatch needs reroll
Comment #10
ankithashettyRe-rolled the patch in #8. Kindly review.
Thank you!
Comment #11
ankithashettyComment #12
Neslee Canil PintoComment #13
javitan CreditAttribution: javitan as a volunteer and at Zoocha commentedFixed patch including reroll. :D
Remember: After apply the patch you will need to add into
MYMODULE_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id)
the new format. Example:$form['MYDATEFIELD']['#attached']['drupalSettings']['better_exposed_filters']['datepicker_options']['dateFormat'] = 'dd/mm/yy';
Enjoy and good luck!
Comment #14
javitan CreditAttribution: javitan as a volunteer and at Zoocha commentedWithout the patch, it is working just doing:
$form['MYDATEFIELD']['#attached']['drupalSettings']['better_exposed_filters']['datepicker_options']['dateFormat'] = json_encode('dd/mm/yy');
onMYMODULE_form_views_exposed_form_alter()
function.Cheers! :D
Comment #15
igonzalez CreditAttribution: igonzalez commented#14 works for me
Comment #16
Neslee Canil PintoThis can be fixed using #14, marking as fixed.
Comment #17
ericdsd CreditAttribution: ericdsd commentedHi @Neslee Canil Pinto maybe i'm wrong but don't you think we should fix the root cause instead of considering that having a workaround is fixing the issue ?
I propose to reopen the issue what do you think ?
Comment #19
viola_chisto CreditAttribution: viola_chisto commented@Gordon and @ariane, #5 did the trick ! Thank so much I was breaking my head !