- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi community,
I'm struggling with creating the date/time field where only the past dates are allowed. I found this code.
But it doesn't work. The accepted behavior is that user is not able to choose from the date/time component the future dates. (This would be happy case) Or at least when user choose date in future he will get the message that future dates are not allowed.
Do you have any suggestions? Thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
53m ago
I did it this way:
Created UI policy:
Where I include every field that needs to be checked.
Than in script I made the if statements:
I know that it can be simplified with for loop 😄
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Same ui policy, but update the text in the script. The condition should be 'start date relative after 1 minute ago' or something similar.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hello @Martines ,
You can use the onChange client script for that :
Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var currentDate = new Date();
var selectedDate = new Date(newValue);
if (selectedDate.valueOf() > currentDate.valueOf()) {
g_form.addErrorMessage('Future dates are not allowed. Please select a past date.');
g_form.clearValue('your_date_field');
}
}
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
thank you for your answer. And if I have more fields where I need to apply this? I don't want to create like 6 ciient scripts for each field I would like to have like on function for that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
53m ago
Client scripts work on the fields themselves, so you will need one for every field. But it makes no sense. You can do this with ui policies.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
