Hi,
How can I prevent users from selecting future dates? Some users of my application mistakenly pick dates beyond today. Records captured either within today or in a previous date. So I want to prevent users from picking any date in the future.
Please help.
Regards.
You might need to use something like new Date() in your dialogue or editor typescript and compare with the selected date and then provide an alert message so if you are using an editor - the validateEntity() method is where you can check and alert or override the before save method ..
Simplified code :
var today = new Date();
if row.Date > today;
Q.Alert("Pick a valid Date, or guess how many fingers I have behind my back")
example of the properties you might like to access
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
DateEditor has a method set_maxDate
@csabc I did not know that - thank you .. one more bit of knowledge in my arsenal ..
@csabc and @stixoffire the MaxValue attribute of the DateTimeEditor doesn't work
@gfo2007 - Sorry but I thought I had responded to this.
There are two different components.
DateEditor and DateTimeEditor Since you are setting date only - use the DateEditor with MaxDate!
If you need the DateTimeEditor then think about checking this MaxValue on the DateTimeEditor might be in Milliseconds so you would need to convert your max date into a value comparable to that. As most time is stored as an integer of milliseconds anyway - the start date is typically 1 January 1970 so milliseconds from that date .. Calculate to a date
@stixoffire DateEditor has MaxValue but unfortunately, it doesn't work. It displays syntax error when typed.
@gfo2007 post a bit of your code here .. I will try to look at it
This is a sample .. in the constructor of the dialog .
this.form.CompletionDate.set_maxDate(new Date());
CompletionDate is DateTime field in my form .
new Date() is how you get the current date .. basically Date.Now()
@stixoffire this is exactly what I needed. This caters for dates that comes before today. So I added another line of code to ensure valid dates are the ones that come before tomorrow.
Thank you.
var today = new Date();
var tomorrow = new Date().setDate(today.getDate() + 1);
this.form.RecDate.set_maxDate(new Date(tomorrow));
Most helpful comment
@stixoffire this is exactly what I needed. This caters for dates that comes before today. So I added another line of code to ensure valid dates are the ones that come before tomorrow.
Thank you.