Skip to main content
Nintex Community Menu Bar

Date/Time Field - I need to limit the time range for every 2 hours

  • Oct 15, 2021 2:11 PM UTC
  • 3 replies
  • 86 views
  • Translate All

I am in need of assistance with limiting the time range on the Date/Time field.

Looking for the time to be every 2 hours from 8am - 4pm. 

Time

8am

10am

12pm

2pm

4pm

This is the code I used:

NWF$("select[name$='Hours'] option").each(function(){     if(NWF$(this).val().match(/^(([0-7,9,11]|12) AM)|(([1,3,5-9]|1[0-1]) PM)/g)) {          NWF$(this).remove();     }});

The above code does not yield the desired results. It still includes 11am.

 

3 replies

Forum|alt.badge.img+6
  • Rookie
  • Oct 15, 2021 2:43 PM UTC

Hi.

This seems to work.

/^((8|10) AM)|(([24]|12) PM)/g

Translate

Asking4aFriend

Could try using: https://www.regextester.com/ to test your Regex expression. 

I tried your code:

 

 NWF$("select[name$='Hours'] option").each(function(){     if(NWF$(this).val().match(/^(([0-7,9,11]|12) AM)|(([1,3,5-9]|1[0-1]) PM)/g)) {          NWF$(this).remove();     }});

 

it not working for me at all. "...name $='Hours' ..." where are you adding this? 

Translate

Asking4aFriend

 I am also trying to limit time range, not successful so far. Where are you adding the code? and 'Hours' is this name part of the date picker function? 

Under Settings, custom JavaScript, I have add the following code:
NWF.FormFiller.Events.RegisterAfterReady(function () {

NWF$('#' + dateCtrl_Start).datepicker('option',{ minDate: new Date(), beforeShowDay: NWF$.datepicker.noWeekends,});
NWF$('#' + dateCtrl_End).datepicker('option',{ minDate: new Date(), beforeShowDay: NWF$.datepicker.noWeekends,});
NWF$('.OnlyHalfHour select.nf-datepicker-select:not(.nf-hours) :not(option[value="00"], option[value="30"])').remove(); // to limit min. to 00 and 30//

NWF$("select[name$='Hours'] option").each(function(){
if(NWF$(this).val().match(/^(([0-7,9,11]|12) AM)|(([1,3,5-9]|1[0-1]) PM)/g)) { NWF$(this).remove(); }});

});

Translate