I have a multichoice field with option selected to add a new option. However often user enter lower case option and I want Titlecase data. I’ve played around with some JS to make this happen without luck.
Any ideas? Its also in a modal. Below is one attempt.
$(document).on(‘knack-scene-render.scene_36’, function(event, scene, record) {
// Get the input field element
// Function to convert input to title case
// Function to convert input to title case
function convertToTitleCase(input) {
// Split the input into an array of words
const words = input.toLowerCase().split(" ");
// Convert the first character of each word to uppercase and join them back
const titleCaseText = words.map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
return titleCaseText;
}
// Get all input fields on the webpage
const inputFields = document.querySelectorAll(“#kn-add-option .kn-input input[type=‘text’]”);
// Attach event listener to each input field
inputFields.forEach(inputField => {
inputField.addEventListener(“input”, function() {
// Get the current input value
const inputValue = inputField.value;
// Convert the input value to title case
const titleCaseValue = convertToTitleCase(inputValue);
// Update the input field value with the title case value
inputField.value = titleCaseValue;
});
});
});
*/