Interaction · Practical
Guide users through a form
Advance a walkthrough when a field changes, validate a form and complete the next step after a successful action.
Try it live
Loading the interactive example…
Make it yours
Download HTMLimport { createTour } from "sitetourkit";
import "sitetourkit/styles.css";
let tour;
const form = document.querySelector("#profile-form");
const status = document.querySelector("#demo-status");
const result = document.querySelector("#profile-result");
document.querySelector("#run-demo").onclick = async () => {
tour?.destroy();
tour = createTour({
progress: true,
steps: [
{
target: "#profile-name",
title: "What should we call you?",
content: "Enter your name, then press Tab to continue.",
advanceOn: { event: "change" },
},
{
target: "#profile-email",
title: "Add your email",
content: "Use a demo address, then press Tab.",
advanceOn: { event: "change" },
},
{
target: "#save-profile",
title: "Try the action",
content: "Create the demo profile. Validation runs before the tour continues.",
advanceOn: { event: "profile:saved" },
},
{
title: "You are all set",
content: "The form was validated and handled locally. Nothing left this browser.",
},
],
});
tour.on("stepChange", ({ index }) => {
status.textContent = `Step ${index + 1} of 4`;
});
tour.on("complete", () => {
status.textContent = "Walkthrough complete.";
});
await tour.start();
};
form.addEventListener("submit", (event) => {
event.preventDefault();
if (!form.reportValidity())
return;
const name = document.querySelector("#profile-name").value;
result.textContent = `Demo profile created for ${name}. No data was sent.`;
result.hidden = false;
document.querySelector("#save-profile").dispatchEvent(new Event("profile:saved"));
});
document.querySelector("#reset-demo").onclick = () => {
tour?.destroy();
form.reset();
result.hidden = true;
result.textContent = "";
status.textContent = "Ready to explore. Select Run example.";
};
window.addEventListener("pagehide", () => tour?.destroy());
Let the user's actions move the tour
This walkthrough introduces two fields, then waits for a successfully validated form action. Enter a name, press Tab, enter a demo email address and press Tab again. Creating the profile advances to the final explanation.
The example handles the form locally. It sends no network request and stores no profile data. Reset restores the empty form.
Connect steps to real events
The first two steps use advanceOn with the native change event. A text field fires this event after its value changes and focus moves away. The action step listens for a custom profile:saved event that the form emits only after validation succeeds.
In a real application, emit the success event after your own save request completes successfully. Keep errors in the current step so the user can correct them.
Integration details
- Use
changefor a completed field edit; use a custom event for an application action. - Keep the highlighted control interactive when it needs user input.
- Avoid modal mode for a step that must interact with an element outside the tour dialog.
- Reuse your application's validation and success events rather than duplicating save logic inside the tour.