Does anyone know if it's possible to limit the time range to, say 7am- 7pm, in a date/time picker?
Solved! Go to Solution.
See if one of the following links is helpful:
Update:
I figured out what I was missing in my regex to exclude the '11 AM' option. By including a '^' before the first grouping, it says the group must start at the beginning of the string. Ergo, if it matches '1 AM', there cannot be anything before it, which means '11 AM' is no longer a match.
I've updated the code blocks below to reflect the new code and have stricken out the portions of text that are no longer valid.
Since you're looking to limit the times instead of the days, you could try the following JavaScript code that I've used in the past.
7 AM - 5 PM:
NWF$("select[name$='Hours'] option").each(function(){
if(NWF$(this).val().match(/^(([1-6]|12) AM)|(([6-9]|1[0-1]) PM)/g)) {
NWF$(this).remove();
}
});
Disclaimer: It's not pretty....but regex rarely is.
**And if anyone is better at regex so the 11 AM doesn't have to be called out separately, please let me know.
This one specifically removes everything outside of the 7 AM - 5 PM window, but the regex can be changed to allow different time frames.
Here's a link to RegEx Tester for the string above. You should be able to use it to test changes for different times.
This RegEx Tester code does not include the newly added '^' before the first grouping. RegEx Tester doesn't treat separate lines as new strings.
7 AM - 7 PM:
NWF$("select[name$='Hours'] option").each(function(){
if(NWF$(this).val().match(/^(([1-6]|12) AM)|(([8-9]|1[0-1]) PM)/g)) {
NWF$(this).remove();
}
});
I just change the ^(([1-6]|12) AM)|(([6-9]|1[0-1]) PM) to ^(([1-6]|12) AM)|(([8-9]|1[0-1]) PM) and it works for your 7 AM - 7 PM window.
Explanation of Code:
this might help as wel - https://community.nintex.com/message/75989-re-set-minutes-in-date-picker?commentID=75989#comment-759...
it's an example for minutes, but for hours it'd be very similar.
Hello Dave
I am trying to implement the hour format to limit only from 10 until 14 as 24hrs time format!
However, when adding your code, it then breaks the datepicker and does not work.
Can you advise please?
NWF.FormFiller.Events.RegisterAfterReady(function (){ NWF$('#' + dateCtrl).datepicker('option',{ minDate: 0, maxDate: '(currDate.getDay() + 35)', beforeShowDay: NWF$.datepicker.noWeekends, onSelect: function(datestr){ startdate = NWF$(this).datepicker('getDate'); }}); }); NWF$("select[name$='Hours'] option").each(function(){ if(NWF$(this).val().match(/^(([10-14])/g) ) { NWF$(this).remove(); } });
am I missing sme kind of }) or something?