Hello there,

First of all thanks for the great module!
There is one thing i can't figure out. I'd like to build a 'jump to date' filter.
For the moment our page looks like http://heibrand.be/kalenders
But i would like to add a block at the top which says:
Find in month: (select month) an (select year) which makes the calendars jump to that month.
At the moment users have to clikc 6-7 times to find out how the calender looks like in july 2013 (for example).

I'm thinking about creating a custom block, with a form which redirects to a page with the correct arguments. But that seems a bit overkill, so i thought asking here first.

Thanks in advance.
Greetings

Comments

de_bernie’s picture

Also searching for this solution...

internal’s picture

Issue summary: View changes

Does anyone have the simple way to do this? Thanks.

saurabh.dhariwal’s picture

If I'm not wrong then you need some good stuff to handle calendar with exposed filter.

You have to place code from above in general form_alter handler (i.e. in mymodule_form_alter) and everything works look like fine.

Code looks like:

<?php
 
function mymodule_form_alter(&$form, &$form_state, $form_id){
...
  if($form_id == 'views_exposed_form'){
    if($form['#id'] == 'views-exposed-form-events-all-search-panel-pane-1'){
      $format = 'm-d-Y';
      $form['date_filter']['min']['#date_format'] = $format;
      $form['date_filter']['max']['#date_format'] = $format;
    }
...
}
 
?>

Beside of this, are you sure that your exposed date filter has identifier 'date_filter_1' ? You can watch the identifier of your filter by clicking on filter in view configuration page. There should be Filter identifier input - copy the value of filter identifier from that input.

Let me know if you face any query regarding this.

Thanks!

internal’s picture

Status: Active » Fixed

Since I pumped this up, I should close it. #3 should work. But I don't want to break the internals. So I write a new form to redirect to the right url to do it. Hope this help others.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

hwasem’s picture

internal,

I'm trying to do the same thing. Would you mind how you wrote a new form to direct the view to the right URL?

Thanks,
Heidi

hwasem’s picture

I was able to figure out something that works for us. I wanted to have the month and year be in a drop-down filter for all data values we had populated.

I created another display block on my calendar view. I crafted the fields for the jump menu (i.e. a field_date formatted to 2015-09 that was hidden and rewritten to be the link "calendar/[field_date], and a September, 2015 date display that was not hidden).

I then changed the view to use the Jump Menu formatter and to "Show" Fields (not the calendar entities). In the Jump Menu settings, I chose my Path field to be the hidden link URL field (field_date). In Jump Menu settings I also chose "Select the current contextual filter value". I created a contextual filter for the date field, used the "Display all results for the specified field " option, and granularity to month. You should be seeing a jump menu in preview as you'd like it.

I put this block on my view and it works great!

I hope this helps someone else who may be looking for it.
Heidi

internal’s picture

Glad you did it. I just learned the form api and wrote custom css and js to do the same thing. It seems your way is more native:)

klidifia’s picture

I don't get it, I just ended up doing it like this:

<select id="month" name="month">
  <option id="01" value="January">January</option>
  <option id="02" value="February">February</option>
  <option id="03" value="March">March</option>
  <option id="04" value="April">April</option>
  <option id="05" value="May">May</option>
  <option id="06" value="June">June</option>
  <option id="07" value="July">July</option>
  <option id="08" value="August">August</option>
  <option id="09" value="September">September</option>
  <option id="10" value="October">October</option>
  <option id="11" value="November">November</option>
  <option id="12" value="December">December</option>
</select>

<select id="year" name="year">
</select>

<button id="gotomonth">Go</button>


$('#gotomonth').click(function() {
  var month = $("#month option:selected").attr('id');
  var year = $("#year option:selected").attr('id');
  location.href = year + '-' + month;
});

var currentMonth = ("0" + (new Date().getMonth() + 1)).slice(-2);
var currentYear = new Date().getFullYear();
for (i = (currentYear - 3); i < (currentYear + 3); i++) {
  $('#year').append('<option id="' + i + '" value="' + i + '">' + i + '</option>');
}
$('#month #' + currentMonth).attr("selected", "selected");
$('#year #' + currentYear).attr("selected", "selected");
rcodina’s picture

@klidifia I had to change this line of code in your example to make it work:

location.href = Drupal.settings.basePath + 'VIEW_URL/' + year + '-' + month;

Also notice you can use the function date_month_names() to get the current language version of each month.

millionleaves’s picture

The solution in #7 worked brilliantly for me - thanks @hwasem. No coding involved. A reminder of just how awesome Views is ...