1

We're using Drupal 9's core Date Range module and need to limit the end date selection to no more than 90 days from today.

I've searched far and wide and have not come up with a workable solution. Seems like it should be simple but I'm stumped.

enter image description here

2
  • 1
    This should be closed because there is no focussed question here. But as a general hint, you should create a custom constraint: drupal.org/docs/drupal-apis/entity-api/entity-validation-api/…
    – Hudri
    Feb 13 at 15:05
  • I read the question as, "How to limit the date selection in the UI widget to +90 days?" In such a case, I don't think a constraint helps because the constraint is applied when the form is submitted, so the widget will still allow selecting an invalid date (which the constraint will block after submission). Feb 13 at 15:22

1 Answer 1

0

Solved it with hook_form_alter():

 $limit = date("Y-m-d", strtotime("+" . 90 . " day"));
 $form['field_job_posting_date']['widget'][0]['end_value']['#attributes']['max'] = $limit;

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