Hello,
My goal is to use javascript to update the "earliest" value of a time picker input to 6 months ago in the event that the user selects a time range with an "earliest" value greater than 6 months ago. I don't want a user to be able to extract more than 6 months of data, but at the same time I want them to be able to use the flexibility of the time picker input.
So far I have:
- Create a token "tok_six_months_ago" under <init> tag on the dashboard which is set to relative_time(now(),"-6mon@mon")
- Defined a time picker input with name "tok_data_period"
- Converted the "tok_data_period" earliest and latest values to epoch via the <change> tag
- <eval token="tok_earliest_epoch">if(isnum('earliest'),'earliest',relative_time(now(),'earliest')</eval>
- <eval token="tok_latest_epoch">if(isnum('latest'),'latest',relative_time(now(),'latest')</eval>
- Created a JavaScript file that monitors changes to "tok_earliest_epoch" and alerts a user when it is out of bounds (it checks earliest against "tok_six_months_ago")
-
def_tok.on("change:tok_earliest_epoch", function() {
if(def_tok.get("tok_earliest_epoch") < def_tok.get("tok_six_months_ago")) {
alert("Lower time limit is out of bounds: data will only be shown for the last 6 months");
}
});
What I would like to do now, but I don't know how, is update the timepicker token on the form (tok_data_period.earliest) with the epoch contained in the "tok_six_months_ago".
Please can somebody help?
Thanks!
Andrew