Catalog Client Script

CesarV_
Tera Contributor

Hi all,

 

I am trying to configure a Date variable on a Catalog Item form so users can only select a date that is at least two weeks out from the current date. Using a Catalog Client Script, I tried scripting this function, which gives me no errors but seems to not change anything on the form. 

 

Can anyone take a look at my script and tell me what I might be doing wrong? 

 

Example: highlighted dates should be grayed out and not selectable:

CesarV__0-1758897188360.png

 

My Script: 

 

function onLoad() {
    var today = new Date();
    var minDate = new Date();
    minDate.setDate(today.getDate() + 14);

    // Format minDate as yyyy-MM-dd
    var yyyy = minDate.getFullYear();
    var mm = String(minDate.getMonth() + 1).padStart(2, '0');
    var dd = String(minDate.getDate()).padStart(2, '0');
    var formattedMinDate = yyyy + '-' + mm + '-' + dd;

    // Set the min attribute on the date input field
    var dateField = g_form.getControl('requested_fulfillment_date');
    if (dateField) {
        dateField.setAttribute('min', formattedMinDate);
    }
}

 

1 REPLY 1

GlideFather
Tera Patron

Hi @CesarV_,

I don't think there would be possible way to "disable" the other options.

 

Instead you can add a field or info message clarifying that the date must be within defined range (2 weeks from today) and if user select any date in that range then doesn't allow to submit.

 

It would be:

  • 1a) onLoad catalog client script to show the field message ALWAYS (upon loading the form)
  • 1b) onChange CCS to show if the particular field is displayed conditionally (e.g. user selects a category in another varibale, this date field becomes visible and was not visible when a form was loaded, otherwise 1a) is enough)
  • 2) onSubmit CCS with return false; which makes the submission impossible

Just a small example, you need to process teh 14 days condition better, it is just to show you hwo to disabel submission

if (g_form.getValue('your_date)' > 14) {
return false;
} else {
return true;
}

 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */