Looking for a way to make users fill in all fields in the AI Chatbot form before the submission? We’ve got a solution!
Just add this code to the Custom JS field on the General tab of your widget’s settings and you’ll be fine:
const waitForElement = (selector, root = document) => new Promise(res => {
const observer = new MutationObserver(() => {
const element = root.querySelector(selector);
if (element) {
res(element);
observer.disconnect();
}
});
observer.observe(root, { childList: true, subtree: true });
});
(function makeInputRequired() {
waitForElement("[class*='form-layout__Form-sc']").then((form) => {
form.querySelectorAll('input').forEach(input => {
input.required = true;
input.setAttribute('aria-required', 'true');
});
form.removeAttribute('novalidate');
});
})();
Note: Custom JS doesn’t function in the preview mode, so you can check the result right on your website or through the Share Link
This video demonstrates the feature in action:
Guys, was this solution helpful? Let us know in the comments ![]()
