Past Date on Date field should thrown an error near field

Gayathri5
Tera Guru

Hi Experts,

 

My requriement is I have only 1 date field whenever i select past date from today it should show field error message. I tried using UI policy but only for 1st time it's working,if i keep on checking again and again the error is not occuring.

Please somebody help me what is the best approach for this?

Regards,

Gayathri

7 REPLIES 7

Aniket Sawant2
Giga Guru

Hi Gayathri,

 

You can use this script in UI policy

condition :

yourdateFieldname before today.

function onCondition() {
g_form.clearValue('u_date');

g_form.showErrorBox("u_date","Please select future date and time",true);

//or u can put following line.

//alert("Please select future date and time");
}

 

Please mark correct/helpful based on impact.

Regards,

Aniket Sawant

I tried this but i was facing some issue so through client script we can achieve. 

can u achieve the same using client script?

Bharath kumar6
Tera Expert

Hi,

You can use onChange client script on the required field and write the code to check if the user is entering the past date.

 

Please mark correct/helpful based on impact.

Regards,

Bharath kumar

Shakeel Shaik
Giga Sage
Giga Sage

Hi Gayathri,

Create onChange Client Script on Field u want to change.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var currentDate = new Date(); //Current Date
    var selectedDate = new Date(g_form.getValue('u_date_field')); //Date field value

    if (currentDate.getTime() >= selectedDate.getTime()) {
        //Past Date on Date field should thrown an error near field
        g_form.showFieldMsg('You can not select a Past Date');
        return false;
    }

}
Thanks,
Shakeel Shaik 🙂