You are viewing limited content. For full access, please sign in.

Question

Question

Apply colors to specific dates on calendar in Laserfiche Forms Professional Version 11.0.2212.30907

asked on May 22, 2024

Hi All,

I am trying to apply a different color for specific dates when we have scheduled a Board Meeting.  I do not want to restrict the other dates; I will only apply colors when the meeting is executed.  

 

I got a script, but  I cannot make it work.  I even tried to apply the colors directly using CSS, but I had no luck.  Here is one of the scripts I used:  

// Function to load jQuery if not already loaded
function loadJQuery(callback) {
    if (window.jQuery === undefined) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "https://code.jquery.com/jquery-3.6.0.min.js";
        script.onload = callback;
        document.head.appendChild(script);
    } else {
        callback();
    }
}

// Your main script that depends on jQuery
function mainScript() {
    $(document).ready(function() {
        // Array of dates when the background color should change
        var agendaDates = ["2024-06-01", "2024-06-15", "2024-07-01"];

        // Function to change the background color of specific dates
        function highlightDates() {
            $(".flatpickr-day").each(function() {
                var cellDate = $(this).attr("aria-label");
                if (agendaDates.includes(cellDate)) {
                    $(this).css("background-color", "#FFDDC1"); // Change to your desired color
                }
            });
        }

        // Initial call to highlight dates after flatpickr initialization
        setTimeout(highlightDates, 100);

        // Trigger the function on month navigation
        $(document).on('click', '.flatpickr-prev-month, .flatpickr-next-month', function() {
            setTimeout(highlightDates, 100); // Adding a small delay to ensure the DOM updates
        });

        // Re-run the highlight function whenever the calendar view changes
        $(document).on('click', '.flatpickr-day', function() {
            highlightDates();
        });
    });
}

// Load jQuery and then run the main script
loadJQuery(mainScript);

 

 

 

0 0

Replies

replied on May 22, 2024

Are you trying to use the Modern/New Designer or the Classic Designer?

And is this your entire script or just part of it?

And did you get this script from another post here on LFAnswers or somewhere else?

I ask these questions because:

If you are using the Modern/New Designer, then you are almost certainly not going to be able to make this work. This is because any Javascript solution can't do these kinds of edits to the structure of the form because the Javascript runs within a sandboxed iFrame that doesn't have direct access to the Document/Form/Fields/DOM/etc..  It can only manipulate the form via the functions enabled in the LFForm interface.  And any CSS-only solutions are unlikely to work as well, because the calendar picker widget is actually held in a completely different area of the DOM than the rest of the form, so the custom CSS you apply to your form is unable to target the necessary components to actually be applied.

If you are using the Classic Designer, and you are listing the full code you are using, then it's missing anything to trigger the code to run (most code examples here on LFAnswers use the document ready function to trigger code to run when the Form first loads).  Also, your code is referencing classes like flatpickr-day and flatpickr-prev-month which do not appear to be the classes used by the Classic Deisgner forms (using the browser Inspector, I see classes like ui-datepicker-calendar and ui-datepicker-today).

If you got this script from elsewhere on LFAnswers, it would be helpful to know the post it came from so that it can be reviewed.  If it came from some other site, it is very unlikely that you can make it work within LFForms without significant modifications.

0 0
replied on May 22, 2024

I am also interested in which form you are using. The script you provided looks like it was retrofitted to work in either designer, but as previously stated JQuery will not work like this in the new designer.

 

That being said, in cloud we have released a new feature that supports using javascript to dynamically enable/disable dates in the calendar picker. With this feature we also plan to add a way to add your own styles to each individual date within the calendar UI.

1 0
replied on May 23, 2024

Zachary, will that be coming to self-hosted as well?

1 0
replied on May 23, 2024

Hi Matthew,

 

Thank you for taking the take to respond to my question.  Yes,  I am using Modern/New Designer.  Also, the script does not come from other posts.  It was me trying to make it work.  It is a self-hosted environment as well.

 

Based on your response, I cannot accomplish what I want with the calendar.  Is there any way I can achieve that?

 

 

0 0
replied on May 23, 2024 Show version history

Based on Zachary's comment - it might be possible in the Modern/New Designer at some future point (assuming the Cloud functionality gets duplicated into Self-Hosted) - but with current functionality, I do not believe this is possible in the Modern/New Designer.

It might be possible in the Classic Designer, simply because that designer has more control over the DOM and form elements.  I haven't ever done this specific use case, but I have written code for the Classic Designer that does black out dates in the calendar picker.  Something like that might be adapted to apply CSS Classes to specific dates to control color and apperance.  I'll see if I can find one of the posts here on LFAnswers where I shared that code for black-out dates.

EDIT TO ADD: Here's the post with the code to blackout dates on the calendar picker in the Classic designer: https://answers.laserfiche.com/questions/170752/Ability-to-restrict-dates-in-forms#171323
I have NOT explored whether or not this will even be possible to tweak this to being able to apply CSS Classes to specific dates - but I know this code works for its purpose of blackout dates in the Classic Designer (I have a couple active forms that use similar functionality).

0 0
replied on May 23, 2024

The date validation functionality will be going to self-hosted in 12 although the styling of dates has not been implemented yet.

 

We are basically mimicking the functionality of the jquery ui calendar picker in the new designer which allows you to set a class on the date in the beforeShowDate function. I would personally keep using the new designer and update the calendar when we implement the feature.

1 0
replied on June 11, 2024 Show version history

The following date functionality will be coming to the new designer in LF12 with the final item coming to Cloud next month.

  1. Using today/tomorrow/relative dates for min/max values without field rules
  2. Using JS to specify valid dates within the given range (i.e., no weekends)
  3. Static styling of the date picker. Dynamic styling when using JS to specify valid dates
    1. You will be able to return an object from JS to specify if it is valid and give it a specific class like is-holiday that can be styled to your liking
2 0
You are not allowed to follow up in this post.

Sign in to reply to this post.