Skip to main content

DHTMLX Booking. Dialog info template example

Live example​

infoTemplate replaces the info block of the booking dialog with HTML of your own. The function receives the selected card and the selected slot, so the block can show any field the record carries, formatted as you need it. This demo prints a large preview image, a cancellation policy, the booked time range, the address, and the price.

const dateFormat = new Intl.DateTimeFormat("en-US", {
    dateStyle: "medium",
});

const timeFormat = new Intl.DateTimeFormat("en-US", {
    timeStyle: "short",
});

function formatDate(slot, { dateFormat, timeFormat }) {
    if (!slot) return "";

    const [start, size] = slot;
    const date = dateFormat.format(start);
    const startTime = timeFormat.format(start);
    const endTime = timeFormat.format(start + size * 60 * 1000);

    return `${startTime} - ${endTime}, ${date}`;
}

function getPhotoElement(preview) {    
    return preview
        ? `<div class="info-photo" style="background-image: url(${preview})"></div>`
        : `<div class="info-photo-empty"></div>`;
}

function infoTemplate({
    item,
    slot,
}) {
    const [cancellationType, ...cancellationText] = cancellationPolicies[item.cancellationPolicy].split(".");
    return `
        <div class="custom-info">
            <div class="info-wrapper">
                ${getPhotoElement(item.preview, "info")}
                <div class="info-header">
                    <span class="info-title">${item.title}</span>
                    <span class="info-category">${item.category}</span>
                </div>
                
                <div class="info-details">
                    <div class="cancellation-policy">
                        <span class="cancellation-policy-type">${cancellationType}.</span> <span class="cancellation-policy-text">${cancellationText.join(".")}</span>
                    </div>
                    <div class="info-date" data-action="reset-slot">
                        <i class="icon wxi-calendar"></i>
                        <span>${formatDate(slot, { dateFormat, timeFormat })}</span>
                    </div>
                    <div class="info-location">
                        <i class="icon wxi-map-marker-outline"></i>
                        <span>${item.details}</span>
                    </div>
                    <div class="info-price">
                        <i class="icon wxi-cash"></i>
                        <span>${item.price}</span>
                    </div>
                </div>
            </div>
        </div>
    `;
}

const { Booking, template, defaultCardShape } = booking;

const widget = new Booking("#root", {
	start: buildToday(),
    data: dataset,
    cardShape: {
        ...defaultCardShape,
        cancellationPolicy: true
    },
    infoTemplate: template(item => infoTemplate(item)),
});

widget.setConfirmHandler(function(event){
    const { confirm } = event;
    setTimeout(() => {
        Math.random() < 0.5 ? confirm.error() : confirm.done();
    }, 1000);
});
<!-- component container -->
<div id="root" style="height:100%"></div>

<style>
.custom-info {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        height: 100%;
    }

    .info-wrapper {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .info-photo,
    .info-photo-empty {
        height: 200px;
        width: 200px;
        margin: 4px;
        overflow: hidden;
        background-repeat: no-repeat;
        background-position: center;
        background-size: cover;
    }

    .info-photo-empty {
        text-align: center;
        border: 1px solid;
        border-color: var(--wx-color-secondary-border-disabled);
        background-image: var(--empty-photo-bg-url);
    }

    .info-header {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding-bottom: 8px;
        gap: 4px;
    }

    .info-title {
        font-size: 16px;
        font-weight: var(--wx-font-weight-md);
        line-height: var(--wx-line-height-md);
    }

    .info-category {
        font-weight: var(--wx-font-weight-md);
    }

    .info-details {
        display: flex;
        flex-direction: column;
        width: 280px;
        gap: 8px;
        border-top: var(--wx-border);
    }

    .cancellation-policy {
        margin: 20px 0 12px;
        font-size: 12px;
        line-height: 16px;
    }

    .cancellation-policy-type {
        font-weight: var(--wx-font-weight-md);
    }

    .info-date,
    .info-location,
    .info-price {
        display: flex;
        align-items: center;
        align-self: start;
    }

    .info-date {
        cursor: pointer;
        color: var(--wx-color-link);
    }

    .icon {
        color: var(--wx-icon-color);
        width: 24px;
        height: 24px;
        font-size: 24px;
        margin-right: 10px;
        align-self: start;
    }

    .icon:before {
        vertical-align: middle;
    }
</style>

<script>
function buildToday(){const params = new URLSearchParams(typeof location !== 'undefined' ? location.search : '');const fixed = params.get('fixedDate') || (typeof window !== 'undefined' && window.FIXED_DATE);return fixed ? new Date(fixed) : new Date();}

	const dataset = [
      {
            id: "ee828b5d-a034-420c-889b-978840015d6a",
            title: "Natalie Tyson",
            category: "Therapist",
            subtitle: "2 years of experience",
            details: "Cleveland Clinic\n9500 Euclid Ave",
            preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/01.jpg",
            price: "$35",
            consultation: true,
            review: {
                stars: 4,
                count: 120,
            },
            slots: [
                {
                    from: 9,
                    to: 20,
                    days: [1, 2, 3, 4, 5],
                },
                {
                    from: 10,
                    to: 18,
                    days: [6, 0],
                },
            ],
        },
      {
            id: "5c9b64ad-1830-4e5b-a5f9-8acea10706df",
            title: "James Anderson",
            category: "Allergist",
            subtitle: "3 years of experience",
            details: "UCLA Medical Center\n57 Westwood Plaza",
            preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/11.jpg",
            price: "$30",
            review: {
                stars: 4,
                count: 64,
            },
            slotSize: 45,
            slotGap: 10,
            slots: [
                {
                    from: "9:15",
                    to: 17,
                    days: [1, 2, 3, 4, 5],
                },
            ],
        },
      // ... 44 more items (see Live Editor for full data)
    ];

    function getDate(addDays, hoursValue = 0, minutesValue = 0) {
        const date = buildToday();
        const secondsValue = 0; // round to minutes
        const msValue = 0;

        date.setDate(date.getDate() + addDays);
        date.setHours(hoursValue, minutesValue, secondsValue, msValue);

        return date.getTime();
    }

    function adjustData(dataset) {
        return dataset.forEach((item, i) => {
            if (item.details && item.details.includes("\n")) item.details = item.details.replace("\n", ".\n");
            item.subtitle = item.subtitle.split(" ").slice(0, 2).join(" ");
            item.cancellationPolicy = (i % 4) + 1;
        });
    }

    const cancellationPolicies = {
        1: "Flexible Cancellation. You can cancel or reschedule your appointment up to 24 hours in advance without any fees. Cancellations made less than 24 hours before the appointment may incur a charge.",
        2: "Strict Cancellation Policy. Appointments must be canceled at least 48 hours in advance. Late cancellations or no-shows will be charged the full consultation fee.",
        3: "Moderate Rescheduling Policy. You can reschedule your appointment up to 12 hours before the scheduled time. Cancellations are not allowed, but you may receive a credit for a future visit.",
        4: "Non-Refundable Appointments. All appointments are final. No cancellations or rescheduling is allowed once the booking is confirmed."
    };

    adjustData(dataset);
</script>

Use case​

The moment before a person confirms is where the terms belong. A clinic states its cancellation window, a workshop lists what to bring, a rental desk shows the deposit. All of it is data you already hold on the record. The template puts it on the one screen people actually read. The same function decides how the chosen time is written, which matters when a booking spans a range.

How to do this in your app​

  • Import the helper: const { Booking, template } = booking gives you the wrapper the property expects.
  • Write the function: it receives { item, slot }, where item is the card record and slot is the selection.
  • Format the time: slot holds the start timestamp and the length in minutes, so start + size * 60 * 1000 is the end, and the demo prints both with Intl.DateTimeFormat.
  • Pass it in: infoTemplate: template(item => infoTemplate(item)).
  • Reuse the widget icons and colors: the demo uses classes such as wxi-calendar and wxi-map-marker-outline and variables such as --wx-color-link, so the block follows the current theme.

Good to know​

  • The template overrides infoShape: with both set, your HTML decides the content and the field switches no longer apply.
  • The card carries whatever you store on it: this demo keeps a cancellationPolicy number on each record and looks the text up in a map of its own before rendering it.
  • The date line leaves the confirmation form: give it data-action="reset-slot". The widget listens for that action and returns to the slot choice, the same way the built-in date line does.

FAQ​

How do you put your own content into a booking confirmation dialog?​

Assign infoTemplate a function wrapped in the template helper. It returns an HTML string, and the widget renders it as the info block of the dialog.

How do you display the selected time range in the dialog?​

Read slot inside the template. It gives the start timestamp and the duration in minutes, which is enough to print a range with Intl.DateTimeFormat or any formatter you already use.

Can the dialog show terms, a policy, or instructions?​

Yes. Store the text or a key for it on the card record, then read it from item in the template and render it wherever the layout needs it.

API reference​

Additional resources​