How to get the Bootstrap 3 Datepicker to redirect to an URL when a date is picked? I use the Drupal bridge module Bootstrap Date &amp; Time picker with its associated JavaScript libraries.  I am trying to create a Drupal form where the user clicks on a particular month, and then the user is redirected to a page showing all the events happening that month.

This is how I build the form:


function rbg_date_picker($form, &$form_state) {
  $form['date'] = array(
    '#type' => 'date_text',
    '#bdtpicker' => TRUE,
    '#date_format' => 'Y-m',
    '#datepicker_chain' => array(
      'my_interval_end[date]' => 'next',
     ),
     '#datepicker_options' => array(
       'viewMode' => 'months',
     ),
  );
  return $form;
}


The form show up and when the user clicks on a month in the widget's grid, the date field gets filled in with the year and month.  So far, so good.

However, at this point, I want the JavaScript to redirect to an URL so that I can create an ordinary page with the relevant information.  For example, if the user picked August 2017, the Javacript should redirect to "http://example.org/2017-08".

Maybe there is already support for this functionality in the Drupal bridge module (and I haven't spotted it), or maybe I need to add a small JavaScript snipped to make this work (confession: I suck at JavaScript).  Any help will be appreciated.

(PS: I know that if I add a submit button to the form, I can pick up the year and month in the submit handler.  However, I think the UX would be better if the user can just click on the month, without having to explictly hit "Submit" afterwards.)
You can redirect using ajax forms and ctools, first of all you will need to add #ajax property to your form field so the code will be : 

function rbg_date_picker($form, &amp;$form_state) {
  $form['date'] = array(
    '#type' =&gt; 'date_text',
    '#bdtpicker' =&gt; TRUE,
    '#date_format' =&gt; 'Y-m',
    '#datepicker_chain' =&gt; array(
      'my_interval_end[date]' =&gt; 'next',
    ),
    '#datepicker_options' =&gt; array(
      'viewMode' =&gt; 'months',
    ),
    '#ajax' =&gt; array(
      'callback' =&gt; 'SOME_FUNCTION_NAME',
    ),
  );
  return $form;
}


The rest is easy, in callback function you will need to have some code like below :

function SOME_FUNCTION_NAME($form,$form_state) {
  $time = $form_state['values']['date']; // maybe need ['und'][0]['value']
  //Some code to fetch desired values from date like month or year
  ctools_include('ajax');
  ctools_add_js('ajax-responder');
  //Some code to fetch desired values from form and compute 'some-valid-url'.
  $commands[] = ctools_ajax_command_redirect('some-valid-url');
  print ajax_render($commands);
  exit;
}