[HOW-TO] Create a custom Calendar using repeating group

Is Full Calendar not giving you enough? Want to have complete customization over your Calendar?

Look no further! I would like to show you a brand new way to create a calendar in your Bubble App using a repeating group and a bit of Javascript.

EVERYTHING IN THIS REPEATING GROUP IS CUSTOMIZABLE
From the text colors, size font, everything is completely customizable just like any other repeating group.

Live Examples:
Preview
Editor

How to accomplish this:

MAKE SURE YOU ARE RUNNING ON BUBBLE ENGINE V1 OR ABOVE

  1. Create a repeating group with 6 rows and 7 columns, set its Type of Content to ā€œDateā€
  2. Create an element state on any element and call it ā€œmonthOffsetā€, set it to a number
    EX: 1f79c63eee15b31c15d12873f1e99b1e
  3. Create 2 buttons/icons that can be used to change month.
  4. Start/Edit the workflow of the two icons to the following:
  • Set State of Element with the monthOffset state, Custom State: monthOffset, Value: Elementā€™s monthOffete (+/- 1 depending whether the button goes forward or backwards)
    EX: 132569654c8090002e7d200fffd23047
  1. Install the ā€œToolboxā€ plugin from the Bubble plugin store

  2. Place an Expression onto the page you want the calendar on

  3. Paste this code into the expression:
    function getDaysInMonth(e,t){var a=new Date(t,e,1),D=,n=new Date(t,e,0).getDate();for(i=a.getDay()-1;i>=0;iā€“)D.push(new Date(t,e-1,n-i));for(;a.getMonth()===e;)D.push(new Date(a)),a.setDate(a.getDate()+1);var g=new Date(t,e+1,1);for(i=D[D.length-1].getDay();6!=i;i++)D.push(new Date(g)),g.setDate(g.getDate()+1);for(i=D.length;42!=i;i++)D.push(new Date(g)),g.setDate(g.getDate()+1);return D}

    getDaysInMonth([MonthAsNum],[YearAsNum]);

  4. Now you need to edit 1 part of the code. Go to the part where it says ā€œ[MonthAsNum]ā€ delete that and replace it with the following Bubble expression:
    Current/date time +(months): *Element*'s monthOffset: extract month - 1
    Then you need to replac ā€œ[YearAsNum]ā€ and replace it with the following Bubble Expression:
    Current/date time +(months): *Element*'s monthOffset: extract year

Now set ā€œResult Typeā€ to ā€˜Dateā€™ and Check the box next to ā€˜Result is a listā€™ as below.
Ex: 8f474597c901f8b7ff7ddf14f6d64d30

  1. ALMOST THERE. Now you need to set the Data source of the repeating group to: Expression Aā€™s Value List (Expression name can be whatever you have it set to)

YOU ARE ALL DONE! However, if it didnt turn out the same, or you want to see from a live example. Click here to see an editor of a working version.

Thank you for reading, if you have questions or issues, reply to this topic!

Thank you,
Nic | nic@codurly.com
codurly.com

86 Likes

Amazing work!

Only took a couple of minutes to copy it from the editor and make it mobile responsive in my app, Can post steps if others want

6 Likes

Very well done. :smiley:

Though I ran into a syntax error when doing a cut/paste. It took me a couple of minutes, but I was able to locate it.

On the second line of the code, it reads: for(i=a.getDay()-1;i>=0;iā€“)

The issue is that it is an em-dash following the last ā€œiā€ in the line above. This should be two en-dashes.

for(i=a.getDay()-1;i>=0;iā€“)

3 Likes

Bummer, i tried to recreate this and nothing is loading in the repeating group and I am getting the following errorā€¦ anyone have any thoughts?

The plugin Toolbox threw the following error: SyntaxError: Invalid or unexpected token
at eval (eval at _.create_code (https://dhtiece9044ep.cloudfront.net/package/run_debug_js/b50053a25e289472b46a845558628ca9b106ab8ec5ea4a7937d3bd1b1e733626/xfalse/x0:96:27803), :13:32)
at https://dhtiece9044ep.cloudfront.net/package/run_debug_js/b50053a25e289472b46a845558628ca9b106ab8ec5ea4a7937d3bd1b1e733626/xfalse/x0:97:15818
at T (https://dhtiece9044ep.cloudfront.net/package/run_debug_js/b50053a25e289472b46a845558628ca9b106ab8ec5ea4a7937d3bd1b1e733626/xfalse/x0:97:8404)

1 Like

nevermind i got it working somehowā€¦ something must have been wrong in the code i guess

BUTā€¦ the month of FEB does not loadā€¦ it does not work on yours either. I dont know if that has to do with it being the previous month from the current date OR just something elseā€¦ but yea? Any ideas on why FEB is just being skipped?

Update: Your demo and my reproduction of your demo are actually skipping over multiple months AND freezing on other months. Are you seeing this?

I noticed it is actually skipping because it is looking for April 31st and the skipping is only happening because today is March 31st. Since April 31st does not exist (only 30 days in April), the month will not show.

There is a discussion here and I am sure someone smarter than me will be able to figure it out for our code.

1 Like

Yep, I noticed it is skipping over months and freezing. This is something that wasnt happening before and must be because it is the 31st.
EDIT:
Nothing is wrong in the custom javascript, it is an error on how my bubble determines the current month to show. The fix seems to be extracting the month before adding the offset. I will update my tutorial soon.

2 Likes

thank you so much for thatā€¦ and thank you very much for the tutorial btw!!! :grinning:

Your CAL with drag N drop groupsā€¦ check it out!!!

DOWNLOAD VIDEO

13 Likes

looks awesome!

How did you create that? In Bubble?

This is nice looking calendar but i did run into an issue with this too that I canā€™t solve. When I click a date I open a pop up window with repeating group for events in it. I just donā€™t know how i can filter those results by day in that case?

yes i just used Levons (zerocode) tutorial calendar and just added a few more things.

2 Likes

Maybe you should release it as a paid plugin if possible - if not, it will be good to hear more on what you did.

This is likely happening as you are trying to say find events whose date = current cellā€™s date. This will only work for events that occur at the exact same date AND exact same time of day.

So when you display the Events in the repeating group, you will need to make sure the Event falls within the date range of that specific day

Here is a quick example of when a date is clicked on the repeating group calendar:

Display List of Events in Repeating group

Source: Do a search for events

Constraints
Start date/time > current cellā€™s date:change hours to 0 change minutes to 0, change seconds to 0
Start date/time < current cellā€™s date:change hours to 23 change minutes to 59 change seconds to 59


Geoff | Top Shelf Templates
Check out a Best Selling Bubble Template
Check out one of The Most Used Bubble Template (FREE)

3 Likes

Thanks for your tips.
I get a bit confused here. I know I need to pass data from calendar to pop-up but i donā€™t know how to do this properly.

I think my issue it that my source for repeating group calendar is date and for my repeating group eventā€™s itā€™s events but I canā€™t make filtering work based on the parentsā€™ cells data because itā€™s not the same source.

Preview:
https://calendar-popup.bubbleapps.io/events_calendar/sample:user

Ps. How do I share link to editor?

Noticed an additional bug.

When back workflow is run from the current month, the calendar does not change. (Ie. if current month is March, and back arrow is clicked, no visible changes to February. But another click advances to January.

When going forward from January, February is completely skipped (no second click needed).

In that Action in your screenshot, For the ā€˜Elementā€™ field, set it as a the Repeating Group in your popup, this repeating group should have the data type as Event

Then for the the ā€˜Data to Displayā€™ field put: Do a Search For Event

In this search, use the constraints I mentioned above.

For a link to the editor, you will need to set your application rights to allow people to view it (under the Settings tab), and just copy the link in your browser while you are on the page in the Editor

Awesome news! Bubble has updated their engine to account for the months not having a date. This was the only problem with creating a calendar with native bubble but it appears that is no more.

IF YOU ARE GOING TO USE THIS PLANNER BE SURE YOU ARE ON BUBBLE ENGINE V1+

You can do this by going into your settings>versions

Read more about it here:

Thank you,
Nic

I canā€™t figure it out but I made this project public. Itā€™s probably easier to help me out. https://bubble.io/page?type=page&name=events_calendar&id=calendar-popup&tab=tabs-2

Ps. I have been checking your CRM template too. It has a lot of functions Iā€™m interested in having.