Hi,
I am trying to display time from a User Input (I’m using the Time Picker element to allow users to input a time easily). The “Time” field as you can see from the picture below. Everything works great up to this part…
When I go to display the time from my database with a text box, it doesn’t allow me to click the “Time” field.
Thanks in advance!
1 Like
That is because the field value is ‘Time’ whereas your element value is ‘Text’.
You can change the time field in your dataset from time to text and that will allow you to use that field through the connect to dataset option that you are using.
However, that will then give you the full time shown, so you will have to use ‘To Locale Time String’ in your page code to show the time as just hours and mins only.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString
Otherwise you can just use code to display the field value in the element and use the to locale time string with that, however note with this option you MUST NOT have it still connected to your dataset through your current setup, otherwise this connect to dataset option will override your code.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItem
$w(" #text 46").text = today.toLocaleTimeString();
I managed it like so by Code
Time = 12:00 (from DataBase field Time)
function FormatTime (time) {
let format = time.split( “:” ).slice( 0 , 2 );
return format.join( “h” );
}
=> 12h00