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

Question

Question

Forms - Save to repository image displaying alternate values of time field

asked on December 26, 2017 Show version history

When I have a field with attribute of time on my form it displays a 12 hour format in the interface while holding a 24 hour format as an alternate value.

When saved to the repository, the 24 hour format is shown. Is there a way to keep the field showing the same as it was displayed on the form? The 12 hour format?

 

0 0

Answer

SELECTED ANSWER
replied on January 4, 2018

There is no built-in "type=time" for div element.

You can try script like this:

$(document).ready(function () {
  $('.timefield input').attr("type", "time");
  
  if ($('.timefield div').text()) {
    var timeString = moment($('.timefield div').text(), 'HH:mm').format('hh:mm A');
    $('.timefield div').text(timeString);
  }
});

 

0 0

Replies

replied on December 26, 2017

Hi Chad,

Did you have customization on the time field? The Forms built-in time field looks different from yours:

If you are using custom script or CSS, you need to make it work on read-only form.

0 0
replied on January 3, 2018

It is a custom field type of attribute "Time". How do I make it work on a read-only form. I thought when you save to repository, it saves an image of the form the user was working with when they click submit.

0 0
replied on January 3, 2018

It's not simply saving an image; it would change the form to read-only first. A major difference is that all input elements are changed to div elements.

Non read-only form:

Read-only form:

If you have customization on the input elements, add similiar customization for div elements as well.

0 0
replied on January 4, 2018

I added this line to the javascript. It is still changing the field to a 24 hour format.

  $('.timefield div').attr("type", "time");

 

Entire code

 


//Wait for page to load
$(document).ready(function () {


$('.timefield input').attr("type", "time");
  
  $('.timefield div').attr("type", "time");

});

 

0 0
SELECTED ANSWER
replied on January 4, 2018

There is no built-in "type=time" for div element.

You can try script like this:

$(document).ready(function () {
  $('.timefield input').attr("type", "time");
  
  if ($('.timefield div').text()) {
    var timeString = moment($('.timefield div').text(), 'HH:mm').format('hh:mm A');
    $('.timefield div').text(timeString);
  }
});

 

0 0
replied on January 5, 2018

This works perfectly, thank you! Is moment.js already included with forms?

0 0
replied on January 7, 2018

Yes it is.

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

Sign in to reply to this post.