slugify chatroom name

modified:   templates/index.html
This commit is contained in:
Russell Ballestrini 2023-12-01 09:25:27 -05:00
parent 12a7bb694b
commit f628791637

View file

@ -6,7 +6,6 @@
<title>Chatroom</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
@ -52,14 +51,18 @@
</form>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$('#join-room-form').submit((e) => {
function slugify(str) {
return str.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, '');
}
document.getElementById('join-room-form').addEventListener('submit', function(e) {
e.preventDefault();
const username = $('#username').val();
const room = $('#room').val();
const username = document.getElementById('username').value;
const room = slugify(document.getElementById('room').value);
window.location.href = `/chat/${room}?username=${encodeURIComponent(username)}`;
});
</script>
</body>
</html>