know when the button is pressed day, week or month in full calendar

0

Good I need for javascript or jquery know if you have clicked or clicked on the day button week or month of fullcalendar.

already the fullcalendar works is created dynamically from javascript adds events etc. in the there are at this moment three buttons see in the next fragment;

header: {
         left: 'agendaDay,agendaWeek,month',
         center: 'title',
         right: ''
        }, 

if I need to click on either the agendaDay, agendaWeek or month to know that click is given because full calendar adds classes and not id and I do not know how to take these values. for example with the following buttons and behind you can do this:

in the html:

<button id='next'><span  class='fc-text-arrow'><strong >›</strong></span></button>

in javascript:

$('#prev').on('click', function() {
        $('#CalendarioWeb').fullCalendar('prev')
        actualizarComboBoxFechas(moment().day())   
    })

But with the week and month day buttons it does not work, nothing comes out in the documentation "according to what I've read" and for javascript try this:

document.getElementsByClassName("fc-agendaDay-button").id="btnDia";

to try to assign id to the button of the day this is added but not within the element in specific so when pulse click does not call any event eye probe with an alert ("etc")

    
asked by Erwis Álvarez 26.11.2018 в 18:44
source

2 answers

0

According to the library of FullCalendar , that is the correct way to get the day, month and year depending on the day that you des click :

$(document).ready(function() {
    $('#calendar').fullCalendar({
     dayClick: function(date, jsEvent, view) {
        console.log(date.month()); //day of the week: 1 for monday
        console.log(date.get('date')); //day of month: 20 for today
        console.log(date.year());
     }
    });
	});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://fullcalendar.io/js/fullcalendar-2.2.5/fullcalendar.css" rel="stylesheet"/>
<script src="https://fullcalendar.io/js/fullcalendar-2.2.5/lib/moment.min.js"></script>
<script src="https://fullcalendar.io/js/fullcalendar-2.2.5/fullcalendar.min.js"></script>
<div id='calendar'></div>

It has its function called dayClick which is the one that takes care of everything.

I hope it serves you. Greetings.

    
answered by 26.11.2018 в 20:27
0

To know which button has been pressed you can use the generic CSS class that the buttons of the bar use and filter by the content of your text. This example will print on the console the text of the button pressed ('week', 'day', 'list', 'month') with which you can filter

  $('.fc-button').click(function(e){
      console.log($(this).text())
  })

And an alternative and valid option is to add an event for each button:

  $('.fc-agendaDay-button').click(function(){
        //hacer lo que debes hacer
  });
  $('.fc-agendaWeek-button').click(function(){
        //hacer lo que debes hacer
  });
  $('.fc-month-button').click(function(){
        //hacer lo que debes hacer
  });

In either case you must place this code once the component is initialized or use the event eventAfterAllRender

    
answered by 26.11.2018 в 20:07