date variable

abhisek
Tera Contributor

Hi All,

I have a date variable 'xyz' which value is getting auto populated based on other 2 variable's values but still not read only. When the value of the date variable 'xyz' is not empty then I need to restrict the user to select any date which is greater than the current value of that date variable xyz that means user can select any date till the date which is already getting auto populating but not greater than that. 

I want to do it using on change client script.

 

Can you please help me out.

Thanks in advance.

 

Regards,

Abhisek Chattaraj.

 

 

 

15 REPLIES 15

Hi @Juhi Poddar 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
 
    if (oldValue && newValue) {
        // Convert the old and new values to Date objects
    var oldDate = new Date(oldValue);
alert('old date is :' + oldDate);
    var newDate = new Date(newValue);
alert('new date is :' + newDate);
        // Compare the new date with the old date
        if (newDate > oldDate) {
            // Show field error message if the new date is greater than the old date
            g_form.showFieldMsg('expiration_date','date cannot be greater than autopopulated value');
            } 
else {
            // Hide the error message if the new date is valid
            g_form.hideFieldMsg('expiration_date');
        }
    }
}