0

I am using fullcalendar and I am able to display events sourcing from a json stream with rails. https://fullcalendar.io/docs/events-json-feed

Now I would like to set the color of a specific event as it's shown in the example. I am specifying it in the json like so:

[{"id"=>101, "style"=>"Phone Call", "location"=>"", "created_at"=>Tue, 26 May 2020 14:31:08 UTC +00:00, "updated_at"=>Tue, 26 May 2020 15:17:48 UTC +00:00, "summary"=>"test", "organizer"=>"somePerson", "job_id"=>194, "start"=>Mon, 27 Jan 2020 18:00:00 UTC +00:00, "title"=>"test", "contacts"=>[], "eventColor="=>"#06fff7"}]

Note that "eventColor="=>"#06fff7" is set.

However, it always displays all events in the same color... not the one specified.

Is it possible to set the event color using the json stream?

I have played with different options such as using colro, backgroundColor etc. I have used hex values or color names (e.g. 'yellow').

No success. I really don't see what I am doing wrong.

Any help is appreciated.

=== UPDATE ===

here is the json that is received by the browser:

eventColor: "yellow"
contacts: []
created_at: "2020-05-26T14:31:08.663Z"
id: 102
location: ""
organizer: "som eperson "
start: "2020-01-27T18:00:00.000Z"
style: null
summary: "test"
title: "test"
updated_at: "2020-05-26T14:31:08.738Z"

the information is displayed properly. However, the color is not recognized.

I am initializing the calendar like so:

var calendar = new Calendar(calendarEl, {
    header: { center: 'dayGridMonth,timeGridWeek,listMonth' },
    plugins: [ listPlugin, timeGridPlugin, dayGridPlugin, bootstrapPlugin ],
    defaultView: 'dayGridMonth',
    height: 'auto',
    width: 'auto',
    editable: true,
    scrollTime: '08:00:00',
    themeSystem: 'bootstrap',
    events: '/jobs/' + jobId +  '/interviews.json',

    }

I removed the bootstrap theme to see if that makes a difference but it does not.

Boenne
  • 605
  • 4
  • 17
  • _Note that "eventColor="=>"#06fff7" is set_ ...sure, but where does it say that "eventColor" is a property recognised by fullCalendar? The list of recognised properties, including the colour-related ones, is here: https://fullcalendar.io/docs/v5/event-parsing – ADyson May 26 '20 at 16:28
  • 1
    "I have played with different options such as using colro, backgroundColor etc. I have used hex values or color names (e.g. 'yellow')."...can you show examples of exactly what you did? Can you show how this rails data is turned into JSON? Have you checked the final JSON being output to see if it contains the properties you expected in the format you expected? (You can use the browser's Network tool to see the response to fullCalendar's AJAX call, and check the final result there). – ADyson May 26 '20 at 16:32
  • If you specify a valid property then I'd expect it to work. I don't know rails, but assuming everything else is done correctly then `"backgroundColor"=>"#06fff7"` or `"backgroundColor"=>"yellow"` ought to work, for example. – ADyson May 26 '20 at 16:33
  • 1
    P.S. I note that your eventColor entry's name actually reads `eventColor=` - there's a stray extra `=` there. If you've been adding that to all your attempts, then it's unsurprising that it doesn't work, even for otherwise-valid property names. That's a typo and needs removing. – ADyson May 26 '20 at 16:35
  • Thanks! I have tried other property names such as 'color' which is referred to on the list you pointed out. The eventColor property is listed here: https://fullcalendar.io/docs/event-display. Adding the json snippet now... – Boenne May 26 '20 at 16:35
  • `The eventColor property is listed here: fullcalendar.io/docs/event-display` ...that's a global option you can set at the calendar level, not a property of an individual event. – ADyson May 26 '20 at 16:36
  • Anyway without further info, at a guess I'd say your problem might relate to the extra `=` I pointed out in my P.S. comment above. Can you confirm? If not you'll have to provide further info as requested. – ADyson May 26 '20 at 16:39
  • Works now! Clearly, I built the json incorrectly. Embarrassing but thanks for pointing it out! – Boenne May 26 '20 at 16:47
  • Well it's more of just a typo than incorrectly structuring the data. P.S. as a (friendly) technical point about terminology, you didn't build any JSON - rails did. You built a rails array containing some hashes, and then presumably rails serialises it to JSON format later on and then outputs the JSON string. – ADyson May 26 '20 at 16:51

0 Answers0