You are viewing limited content. For full access, please sign in.

Question

Question

single line default to current time

asked on April 19, 2018 Show version history

I have a single line field that I'm using as a time selector using the following javascript:

$(document).ready(function () {
  $.getScript('https://docs.________.com/Forms/lib/jquery-timepicker/jquery.timepicker.js', function() {
    $('.time input').timepicker({ 'step': 5, 'scrollDefault': 'now' });
  });
}); 

This works great and creates a drop-down time selector with 5 min increments. I'd like to have the form open and that field pre-populated with the current time. How would I go about doing this?

0 0

Answer

SELECTED ANSWER
replied on April 20, 2018 Show version history

So I've figured out a solution for anyone who needs this. I used a Single Line field for the time and gave it the css class "time". I used the following Javascript:

$(document).ready(function(){
  
  function setcurrenttime (){
	  var currentdate = new Date();
	  var hours = currentdate.getHours();
	  var minutes = currentdate.getMinutes();
  	  var ampm = hours >= 12 ? 'pm' : 'am';
	  hours = hours % 12;
	  hours = hours ? hours : 12; // the hour '0' should be '12'
	  minutes = minutes < 10 ? '0' + minutes : minutes;

	  var datetimenow = hours + ':' + minutes + ampm;

	  $('#Field11').val(datetimenow);
  }
  setcurrenttime();
})

$(document).ready(function () {
  $.getScript('https://docs._________.com/Forms/lib/jquery-timepicker/jquery.timepicker.js', function() {
    $('.time input').timepicker({ 'step': 5, 'scrollDefault': 'now' });
  });
}); 

The top portion brings in the time in am/pm format to match the drop-down which is created by the second portion. You can see the time is 11:09am, and then the drop-down is incremented by 5 minute segments

1 0

Replies

replied on April 20, 2018

Hi David, 

 

I was interested by your question and came to the below conclusion.

 

I tried a few solutions while testing and here might be the solution to your problem if a single line field variable is not required.

And the results in the preview was as follow:

1.) The time field variable:

 

2.) The date field variable with the "Show Time" checkbox ticked:

 

Kind Regards,

Tiaan Sheppard.

1 0
replied on April 20, 2018

So the reason a single line field is required is because the default time field in Forms only has 1 hour increments. If there is a way to change this, that would be great. I honestly am not sure why they would have a time field where you can't adjust the increments...

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.