Skip to main content
rakeshk21205956
Inspiring
May 10, 2017
Answered

Setting Date Range Validation in a Text field

  • May 10, 2017
  • 1 reply
  • 2892 views

I have a field called Text3 (date field with format mm/dd/yyyy) , and another field Text 4

my condition are ,   user inputs any date in Text3 ... then  the Text4 default date will be  Text3 + 30 days, but the user can alter the Text 4 field with the range of Text3 to Text3 + 45 days ..

For ex - If Text  3 = 01/01/2017,   then Text4 (default value) = 01/31/2017  but user can put any value (if he wants) in the range 01/01/2017  to 02/15/2017 i.e Text 3 +45 days

Following is my script in put this in custom calculation tab:

var sDate = this.getField("Text3").value; // get date string

var oDate = util.scand("mm/dd/yyyy", sDate); // convert to object

var nDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds

var nDate = oDate.getTime() + (30 * nDay); // add 7 days as milliseconds

oDate = new Date(nDate); // convert milliseconds to date object

defau= util.printd("mm/dd/yyyy", oDate); // format result

var endDate = this.getField("Text3").value; // get date string

var pDate = util.scand("mm/dd/yyyy", endDate); // convert to object

var eDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds

var eDate = pDate.getTime() + (45 * eDay); // add 7 days as milliseconds

pDate = new Date(eDate); // convert milliseconds to date object

end= util.printd("mm/dd/yyyy", pDate); // format result

var startDate = this.getField("Text3").value; // get date string

stDate = util.scand("mm/dd/yyyy", startDate); // convert to object

if (stDate <= event.value <= end) {event.value = event.value}

else { event.value = defau}

But somehow this is not working...... .. plz help..

This topic has been closed for replies.
Correct answer rakeshk21205956

it is shame on you people who call themselves an expert......... behaving such rudely and arrogantly.....................

i didnot had knowledge of your field (in which u call urself expert) .. thatswhy i asked for little help..... not also help only wanted you to point out the errors and some solution to it.... but instead you people showed ur arrogance and rude behavior.....

what you people think we can't do anything without your help......

and for your kind information i have completed the above task successfully.........  and you would feel ashamed to know that there was no error in my script.... only the <= sign was misplaced...... due to which it skipped that part and went to the defau part........


here is the final script you arrogant "try67"  ..there was nothing wrong with my script but you bullied me......i just gave the above script a different format...

var d = util.scand("mm/dd/yyyy", event.value);

var s = util.scand("mm/dd/yyyy", this.getField("Estimated delivery date").value);

var e = util.scand("mm/dd/yyyy", this.getField("Text14").value);

if (s.getTime()<= d.getTime()&& d.getTime() <= e.getTime()) {event.value=event.value}

else {event.value = this.getField("Text13").value};

1 reply

Bernd Alheit
Community Expert
Community Expert
May 10, 2017

Check the JavaScript console for errors.

rakeshk21205956
Inspiring
May 10, 2017

plz point out the error in the script..... console window doesnot show anything.. i mean i am not able to understand the error in the console window

rakeshk21205956
Inspiring
May 10, 2017

the problem is the script is not taking consideration the validation part... it always shows the default value i.e Text3 + 30 days......