HarryR
April 28, 2022, 9:29am
1
I haven’t found this in the forum so I thought I’d add it for reference. Here’s some Javascript code for changing the default interval time in the time field.
`$(document).on(‘knack-view-render.view_xxx’, function(event, view, data) {
$(’#view_xxx-field_yy-time ’).timepicker({
interval: 30,
minTime: ‘9:00am’,
maxTime: ‘7:00pm’,
});
});
$(document).on('knack-view-render.view_xxx
‘, function(event, view, data) {
$(’#view_xxx-field_yy-time-to ’).timepicker({
interval: 30,
minTime: ‘9:00am’,
maxTime: ‘7:00pm’,
});
});`
3 Likes
Thanks @HarryR - I’ll give it a try….nice one
Sorry, but I am not familiar with Javascript. I am trying this, but have not been able to make it work. Any help you can provide will be greatly appreciated.
Here are the two fields I would like to apply this code to…
Visit Start Time:
https://builder.knack.com/.../pages/scene_45/views/view_63/form/inputs/rows/0/columns/0/inputs/5
Visit End Time:
https://builder.knack.com/.../pages/scene_45/views/view_63/form/inputs/rows/0/columns/0/inputs/6
This is the code I added to the App Settings/API & Code/JavaScript area.
$(document).on(‘knack-view-render.view_63’, function(event, view, data) {
$(’#view_63-field_5 ’).timepicker({
interval: 30,
minTime: ‘9:00am’,
maxTime: ‘7:00pm’,
});
});
$(document).on(‘knack-view-render.view_63’, function(event, view, data) {
$(’#view_63-field_6 ’).timepicker({
interval: 30,
minTime: ‘9:00am’,
maxTime: ‘7:00pm’,
});
});
Hi Nathaniel, you’re missing the “time” and “time-to” for the timepicker, here’s the code you need:
$(document).on(‘knack-view-render.view_63’, function(event, view, data) {
$(’#view_63-field_5-time ’).timepicker({
interval: 30,
minTime: ‘9:00am’,
maxTime: ‘7:00pm’,
});
});
$(document).on(‘knack-view-render.view_63’, function(event, view, data) {
$(’#view_63-field_5-time-to ’).timepicker({
interval: 30,
minTime: ‘9:00am’,
maxTime: ‘7:00pm’,
});
});
And repeat the same for field_6 Hope that helps!
Sorry to bump this one @HarryR .
minTime
and maxTime
seem to work okay, but interval
has no impact.
I found a post about using step
instead, and that seems to work.
Wondering if anyone else has experienced the same with interval
?
$(`#${view.key}-field_179-time`).timepicker({
step: 15,
minTime: '07:00AM',
maxTime: '07:00PM',
});
1 Like
Nice one @StephenChapman - I’ve been hoping that there was a solution. Interval used to work but stopped some time ago.
I’ll give “step” a try.