0

I have added a date element to my webform.

Now I want to change the date format for the date element.

I have used the following code.

function my_module_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
  if ($element['#type'] === 'date') {
    $element['#date_date_format'] = 'd/m/Y';
  }
}

But I can still see the date element like this.

enter image description here

And when I try to submit the form and I get an error on date field.

Also is there a way to change the date format in the email which webform sends?

0

The date format in the field depends on the operating system settings. So it will display the date format according to the format set in your OS.

For the date format in the email, You need to change it from admin/structure/webform/config/elements in the Element formats section by setting the default format for the date field.

0

I am assuming you are using Webform 6.x/

For Drupal 9.x, you need to install the jQueryUI datepicker module and then enable the datepicker via the UI.

For Drupal 8.x, the jQueryUI datepicker is included.

2
  • I am using Webform 5.x. – Ahmad Mar 4 at 4:34
  • Did you enable the date picker? – jrockowitz Mar 5 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.