How to build calendar view from text fields?

Created on 18 July 2024, 3 months ago
Updated 10 August 2024, 2 months ago

Ok, let me know: how to build calendar view from text fields with dates?

I determine text fields on node with this values:

Then i build view

And… Nothing…

Whats wrong with this approach and how to obtain Event duration field?
If values in my fields are incorrect, can you write right format for any date, that should be work?

💬 Support request
Status

Closed: works as designed

Version

5.1

Component

Miscellaneous

Created by

🇺🇦Ukraine vasyok

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @vasyok
  • 🇦🇺Australia mingsong 🇦🇺

    First of all, text field as a data field is not supported.

    Have a look at the document below might help.

    https://fivejars.com/blog/all-you-need-know-about-fullcalendar-view-module

    Secondly, this is a support request issue.

  • 🇺🇦Ukraine vasyok

    Text field as the date field is not supported?
    But on the module page it is written:

    You need a long plain text field to present the RRULE string for recurring logic of an event. For example,
    DTSTART:20200302T100000Z
    EXDATE:20200309T100000Z
    EXDATE:20200311T100000Z
    RRULE:FREQ=WEEKLY;UNTIL=20200331T120000Z;INTERVAL=1;WKST=MO;BYDAY=MO,WE

    Why EXDATE is writen twice?

    Ok, i provide new long plain text field vith value from readme...

    ...and rebuild view

    And… Nothing… Again.

  • 🇦🇺Australia mingsong 🇦🇺

    You need to learn what “RRULE” means.

    This is a free contribution module built and help by volunteers.

    Any bug report and feature request is welcome, because they will help others in the Drupal community.

    I am close this issue as it is obvious misunderstanding.

  • Status changed to Closed: works as designed 3 months ago
  • 🇦🇺Australia mingsong 🇦🇺
  • 🇺🇦Ukraine vasyok

    Ok, i did it without module.

    Here is my workflow.

    Text fields on node

    I think, that it will works with date_recur fields.

    View with hidden fields

    Global: custom text field is rewritten in template views-view-field--NAME-OF-VIEW--block-1--nothing.html.twig:

    {{ attach_library('symnews/fullcalendar') }}
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            var calendarEl = document.getElementById('calendar');
    
            // Function to calculate duration from DTSTART and DTEND
            function calculateDuration(dtstart, dtend) {
              var start = new Date(dtstart);
              var end = new Date(dtend);
              var durationInMs = end - start;
              var durationInHours = durationInMs / (1000 * 60 * 60);
              return durationInHours + ':00';
            }
    
            // Event details
            var dtstart = '{{ view.field.field_start_text_field.original_value }}';
            var dtend = '{{ view.field.field_end_text_field.original_value }}';
            var duration = calculateDuration(dtstart, dtend);
            var rrule = '{{ view.field.field_rrule_text_field.original_value }}';
            
            var calendarConfig = {
              firstDay: 1,
              headerToolbar: {
                right: 'dayGridMonth,timeGridWeek,timeGridDay',
                center: 'title',
                left: 'prevYear,prev,next,nextYear'
              },
              initialDate: dtstart,
              events: []
            };
    
            if (rrule) {          
              var rruleString = 'DTSTART:' + dtstart + '\nRRULE:' + rrule;
              calendarConfig.events.push({
                title: '{{ view.field.title.original_value }}',
                rrule: rruleString,              
                duration: duration // Use calculated duration
              });
            } else {          
              calendarConfig.events.push({
                title: '{{ view.field.title.original_value }}',
                start: dtstart,
                end: dtend,
                duration: duration // Use calculated duration
              });
            }
    
            var calendar = new FullCalendar.Calendar(calendarEl, calendarConfig);
    
            calendar.render();
        });
    </script>
    
    <div id='calendar'></div>


    MYTHEME.libraries.yml:

    fullcalendar:
      version: 1.x
      header: true
      js:                         
        https://unpkg.com/fullcalendar@5.11.5/main.min.js: {}   
        https://cdn.jsdelivr.net/npm/rrule@2.6.4/dist/es5/rrule.min.js: {}   
        https://cdn.jsdelivr.net/npm/@fullcalendar/rrule@5.11.5/main.global.min.js: {}
      css:
        theme:      
          https://unpkg.com/fullcalendar@5.11.5/main.min.css: {}

    Result here:

    https://planetallgaeu.de/timely-import/kurkonzert-im-kurpark-bad-wurzach

    if node will not exist - it looks like:

Production build 0.71.5 2024