Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Created May 14, 2026 13:54
Show Gist options
  • Select an option

  • Save Crocoblock/2369fffd39343257338563466320afdb to your computer and use it in GitHub Desktop.

Select an option

Save Crocoblock/2369fffd39343257338563466320afdb to your computer and use it in GitHub Desktop.
JetFormBuilder / JetAppointments - get the number of Slots and Hours from appointment calendar
document.addEventListener("DOMContentLoaded", function () {
if (!window?.JetPlugins?.hooks) {
return;
}
const { addAction } = JetPlugins.hooks;
addAction(
"jet.fb.input.makeReactive",
"jet-form-builder/jet-appointments-booking/custom-get-count",
function (input) {
if (!input?.nodes?.length) {
return;
}
if (input.nodes[0]?.attributes['data-field']?.value == 'appointment') {
input.watch(() => {
let countSlots = [], countTime = [], dates = [];
const formId = input.root.rootNode.dataset.formId,
appointments = input.nodes[0].value ? JSON.parse(input.nodes[0].value) : [];
appointments.forEach(element => {
countTime.push((element.slotEnd - element.slot) / 60 * (element.count || 1));
countSlots.push(element.count || 1);
dates.push(element.date || '');
});
if (window.JetFormBuilder[formId].dataInputs?._jet_app_count_slots) {
window.JetFormBuilder[formId].dataInputs._jet_app_count_slots.value.current = countSlots.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
}
if (window.JetFormBuilder[formId].dataInputs?._jet_app_count_time) {
window.JetFormBuilder[formId].dataInputs._jet_app_count_time.value.current = countTime.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
}
if (window.JetFormBuilder[formId].dataInputs?._jet_app_date) {
window.JetFormBuilder[formId].dataInputs._jet_app_date.value.current = dates.join(', ');
}
});
}
}
);
});
@Crocoblock

Copy link
Copy Markdown
Author
  1. Add field hidden field _jet_app_count_slots and _jet_app_count_time, set Manual input and leave empty input https://i.imgur.com/d3dOb5Y.png
  2. Add code in html block (widget). Don't forget add <script> before the code and </script> after. https://i.imgur.com/gsnMier.png

Result: https://i.imgur.com/gGDdRXp.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment