KadongK
BuildShip17mo ago
3 replies
Kadong

How to add custom field for POST on chat widget assistant?

I'm trying to add a custom input inside the form when that chat widget is rendered. It doesn't show on my logs. This is the remix link https://buildship.app/remix/2618166a-add2-4e3b-9d8b-c3b1cae9490c

Here's my script:
function addCustomField() {
const inputElement = document.getElementById("buildship-chat-widget__input");
if (inputElement) {
// Check if the hidden input already exists by name or id
if (!document.querySelector('input[name="user_role"]')) {
// Create hidden input element
const hiddenInput = document.createElement("input");
hiddenInput.type = "hidden";
hiddenInput.name = "user_role"; // Add name attribute
hiddenInput.value = "default_role"; // You can customize this value as needed

// Insert the hidden input after the input element
inputElement.parentNode.insertBefore(hiddenInput, inputElement.nextSibling);

console.log("Hidden input 'user_role' added.");
} else {
console.log("Hidden input 'user_role' already exists.");
}
} else {
console.error("Chat input field not found.");
}
}

Thank you in advance!
image.png
Visually build workflows and powerful backend logic for your apps. Powered by AI, connect to anything with or without code.
BuildShip - Visual backend workflow builder
Was this page helpful?