Implementing Bootstrap Popover on Rails FullCalendar

Fullcalendar is absolutely stunning. I recently tried it out and now I would like to add a popover to provide event descriptions when clicked. Here's an example of what I'm aiming for: Although I'm not well-versed in json and javascript, I am eager to learn more about them. Can anyone offer assistance?

Popover calendars.js.coffee

$(document).ready ->
  $('#test').fullCalendar
    header: 
      left: 'prev,next today',
      center: 'title',
      right: 'month'
    defaultView: 'month',
    height: 500,



    buttonText: {
        month: 'month',
        today: 'today'
    },

    eventSources: [{
      url: '/school/calendars',
    }],


    firstHour: 6,
    slotMinutes: 30,
    defaultEventMinutes: 120,
    axisFormat: 'H', 
    timeFormat: 'H(:mm)',
    dragOpacity: {
        agenda: 0.5
    },
    minTime: 0,
    maxTime: 24

on model/event.rb

scope :between, lambda {|start_time, end_time|
    {:conditions => [
  "starts_at > ? and starts_at < ?",
  Event.format_date(start_time), Event.format_date(end_time)
] }
  }

  # overriding the json view is necessary to meet full_calendar's expectations.
  def as_json(options = {})
    {
      :id => self.id,
      :title =>  self.name ,
      :description => self.description || "",
      :start => starts_at.rfc822,
      :end => ends_at.rfc822,
      :allDay => self.all_day,
      :recurring => false,
      #:color => "red"
    }

  end

  def self.format_date(date_time)
    Time.at(date_time.to_i).to_formatted_s(:db)
  end

on controller/school/calendars_controller.rb

@events = Event.scoped
@events = Event.between(params['start'], params['end']) if (params['start'] && params['end'])
    respond_to do |format|
              format.html # index.html.erb
              format.json { render json:  @events }
     end

this is popover

<div class="popover right">
     <div class="arrow"></div>
         <h3 class="popover-title"> <%= @event.nama %> </h3>
            <div class="popover-content">
              <p>Start at : <%= @event.starts_at %>
              End at : <%= @event.ends_at %>
              Description : <%= @event.description %>
              <br/>
              </p>
            </div>
</div> 

Answer №1

To customize individual events, make use of the eventRender callback in FullCalendar.

$('#calendar').fullCalendar({
    ...
    eventRender: function (event, element) {
        element.popover({
            title: event.name,
            placement: 'right',
            content: '<br />Start: ' + event.starts_at + '<br />End: ' + event.ends_at + '<br />Description: ' + event.description,
        });
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Scrolling and looping through an array using jQuery or JavaScript

Using Lettering.js, I have successfully generated a set of <span> elements with the class "char*", where * represents an integer. The array of these elements is created in the following manner: var characterArray = $("[class^='char']"); B ...

invoke a function upon successful completion of an ajax call in a datatable

Can we trigger a JavaScript function after a successful AJAX call in a datatable? Here is the code I am attempting to use: var dataTable = $('#app-config').dataTable( { "bAutoWidth": false, ...

Adding up nested arrays based on their respective indices

If I have two nested arrays within a corresponding array like this: const nums = [ [4, 23, 20, 23, 6, 8, 4, 0], // Each array consists of 8 items [7, 5, 2, 2, 0, 0, 0, 0] ]; How can I add the values based on their indexes? Expected Result: ...

What could be the reason behind the failure of $cookieStore.get() in retrieving the value?

I am currently testing the cookie functionality in AngularJS. I'm encountering an issue where the console is returning 'undefined' when trying to retrieve a saved value from the cookie using $cookieStore.put(). It seems to work fine when set ...

Ways to reset the selected option when the user chooses a different option using either Jquery or Vanilla JavaScript

I am currently working on a functionality to clear the select option when a different brand is selected. The issue I am facing is that when I choose another brand, the models from the previous selection are not cleared out. For example, if I select BMW, I ...

Mapping an HTTP object to a model

Currently facing an issue with mapping an http object to a specific model of mine, here is the scenario I am dealing with: MyObjController.ts class MyObjController { constructor ( private myObj:myObjService, private $sco ...

Transforming the font landscape with Twitter Bootstrap 3's Glyphicons

I have an unordered list with icons styled using Twitter Bootstrap 3. The Carme font from Google Fonts is used for normal text, and works well in that context. However, when I add icons to the unordered list using BS3, the font-family of that particular ...

Tips for effectively managing Angular JS dependencies and promoting modularity

As I embark on a new project from the ground up, my main focus is creating a responsive website optimized for mobile devices. In order to achieve this goal, I am seeking information about Angular: How does Angular manage its resources and dependencie ...

What is the best method for retrieving a JSON array from a query?

Within a postgres 10 database, there are three tables: Main Table: id | name ----------- 1 | first 2 | second 3 | third … Substances Table: id | name ---------------------- 1 | gold 2 | silver 3 | aluminum … Link Table: id | id_main ...

What solutions are available to resolve the routing problem in React.js?

On my fourth day working with Node and React.js, I am creating a custom offline search function for Docusaurus 2. I've built a JSON index and implemented a search function using elasticlunr. My goal is to redirect to a separate results page, but I&apo ...

How should you correctly display the outcome of a mathematical function on a data property in a v-for loop in VueJS?

Recently, I've been developing a dice roller using Vue for a game project. The approach involves looping through different types of dice with v-for to create buttons and display the result in an associated div element. However, despite correct console ...

utilizing JSON data in a React application

I am working on a React project that involves a parent to grandchild hierarchy. In my code, I am passing values as JSON Objects. There are two input boxes where users can enter values and a button that stores and displays the values when clicked. Below is ...

CsvIssue: Opening Quote Error: a quotation mark was detected within a field on line 9618

Encountering an error while attempting to parse kepler_data.csv using csv-parse with promises, as instructed by Adam and Andre Negoi in the NodeJS course. Below is the code snippet: function loadPlanetsData() { return new Promise((resolve, reject) => ...

Challenge with Body Parameter in POST Request

I've been working on creating a new team within our Azure Devops instance using the Devops REST API. I'm using R with 'httr' for the POST request and 'jsonlite' for the toJSON function. Despite following Microsoft's docu ...

What is the best way to determine if an asp:Checkbox has been selected and then use JavaScript to display or conceal it?

On my aspx page, I have an asp:checkbox and an asp:textbox. I am trying to figure out how to display the textbox when the checkbox is checked and hide it when the checkbox is unchecked using Javascript. Any assistance would be greatly appreciated. ...

The behavior of Elementor lightbox buttons upon being clicked

When using Android, I've noticed that the lightbox briefly displays a semitransparent cyan bar on the left and right buttons when they are pressed. Is there a way to control or prevent this behavior? Any suggestions would be appreciated! Thanks in adv ...

What steps can be taken to resolve an error encountered when attempting a dynamic data POST request from the body

Whenever I attempt the post method to fetch data on Postman and store it in a local MongoDB database, I encounter an error. The error message indicates a bad request with a status code of 400. *The following is app.js: var express = require('express& ...

Execute a function on every item within a loop by utilizing jQuery

My view-model includes a data grid similar to the one displayed below <table> @foreach (var item in Model) //for(int i=0;i<Model.Count();i++) { using (Html.BeginForm("Edi ...

Solve integers and booleans within a deeply nested NSDictionary

Suppose you have loaded a JSON string into an NSDictionary containing numbers represented as strings. The resulting NSDictionary would resemble the following: NSDictionary* example = @{ @"aNumber": @"1", @"aFloat": @&q ...

Can a shape similar to an inverted circle be created using CSS and jQuery?

I'm stumped on how to create an inverted circle in the corners. I've included a picture for reference. https://i.stack.imgur.com/jeNdh.jpg Is it feasible to achieve this effect using CSS3 or maybe jQuery? ...