Vynnette26
Rookie

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

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.

 

0 Kudos
Reply
3 Replies
ethurber
Scout

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

Hi.

This seems to work.

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

0 Kudos
Reply
Asking4aFriend

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

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? 

0 Kudos
Reply
Asking4aFriend

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

 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(); }});

});

0 Kudos
Reply