Skip to main content

Hello. I am using the form's Custom JavaScript section to check the date/time (we have a service at my hospital that is available certain days/times). I have that js working fine and I end up with a true or false. If true, I want to show panelA. If false, I want to show panelB. I am having trouble with the syntax.

  if IE 9]  endif] 

NWF$(document).ready(function() {

var dt = new Date();
var w = dt.getDay();
var h = dt.getHours();
var m = dt.getMinutes();
var isAvailable = false;

if (w === 1 || w === 2 || w === 3 || w === 4 || w === 5) {  /* is time b/t 9:45 and 4:45? */
  if (h >= 9 && h <= 15) {
    isAvailable = true;
  } else if (h === 16 && h <= 45) {
    isAvailable = true;
  }
} else {
  /*not available on weekends*/
  isAvailable = false;
}
window.alert(isAvailable);
 
});
I want to use the isAvailable boolean to show panelA or panelB and am not getting the syntax right. Can anyone help?

I should add that the panels' visibility properties are set to No by default.


I believe that this should accomplish what you'd like to. 

var dt = new Date();
var w = dt.getDay();
var h = dt.getHours();
var m = dt.getMinutes();
var isAvailable = (w >= 1 && w <= 5) && ((h === 9 && m >= 45) || (h>9 && h<16) || (h === 16 && m <=45));

window.alert(isAvailable);
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

is w greater or equal to 1 && also lesser than or equal to 5? 


and is either -

h exactly equal to 9 && m greater or equal to 45? 

h greater than 9 && also lesser than 16?

or 

h exactly equal to 16 && m lesser than or equal to 45? 


Hi. Thank you for replying. What I'm wanting to do is show the panels based on the Boolean result but I'm having an issue with the syntax for that.


I think there is no need for javascript for what you want to achieve.

have a look here how could you easily check for a time range within a day with a rule

https://community.nintex.com/message/55543-re-suppress-submit-control-based-on-time-of-day?commentID=55543#comment-55543 

it could easily be extend by check for a workday using formatDate() function, have a look here for a proper format string

 


I appreciate your reply. I can look into other ways of doing this but ... Is there no way to show or hide a panel in the JavaScript? I thought it was just my syntax was at issue but maybe not.


Hi Mindy,

how about you use a rule on that panel to show/hide it? In your JS validation you could set the value of some hidden field and use this value inside your rule to decide whether to show or hide the panel.

Cheers

Philipp


of course you can achieve with javascript whatever you like, even hiding/showing panel.

however problem with javascript is so that it's your customization and nintex do not support neither take any consideration of it. so what's working now is not guaranteed to work with following update/upgrade.

so, whenever there is OOTB solution available (rules in your case) it should be used and javascript avoided.


Fair points. Thanks.


Hi Mindy,

You could give your panel a CSS class in its Control Settings / Formatting section and then show/hide the panel from JavaScript controlling it via CSS attributes.

Kind regards

Jean-Pierre


Reply