Character count and whitespace sanitization

This commit is contained in:
erew123 authored and GitHub committed 2024-12-12 06:28:32 +00:00
1 parent 27df5b8038
commit 6052453d26
1 file changed
+17 -1
+17 -1
View File
@@ -92,7 +92,8 @@
<input type="text" id="model" name="model" value="some-model" required><br> <input type="text" id="model" name="model" value="some-model" required><br>
<label for="input">Input Text:</label> <label for="input">Input Text:</label>
<textarea id="input" name="input" rows="4" required>Hello, this is a test.</textarea><br> <textarea id="input" name="input" rows="8" required>Hello, this is a test.</textarea><br>
<p id="charCount">Character count: 21</p>
<div class="form-group"> <div class="form-group">
<div> <div>
@@ -132,12 +133,26 @@
</div> </div>
<script> <script>
// Real-time character count
const inputField = document.getElementById('input');
const charCountDisplay = document.getElementById('charCount');
inputField.addEventListener('input', () => {
const trimmedInput = inputField.value.trim();
charCountDisplay.textContent = `Character count: ${trimmedInput.length}`;
});
document.getElementById('ttsForm').addEventListener('submit', async function (event) { document.getElementById('ttsForm').addEventListener('submit', async function (event) {
event.preventDefault(); event.preventDefault();
const formData = new FormData(event.target); const formData = new FormData(event.target);
const jsonData = {}; const jsonData = {};
// Sanitize input: trim spaces
formData.forEach((value, key) => { formData.forEach((value, key) => {
if (key === 'input') {
value = value.trim().replace(/\s+/g, ' '); // Trim and normalize spaces
}
jsonData[key] = key === 'speed' ? parseFloat(value) : value; jsonData[key] = key === 'speed' ? parseFloat(value) : value;
}); });
@@ -176,5 +191,6 @@
} }
}); });
</script> </script>
</body> </body>
</html> </html>