Skip to content

Commit 9b28276

Browse files
changing way we handle empty form submission attempts; required attribute is behaving oddly
1 parent bb97a8a commit 9b28276

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

overscroll-behavior/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h2>Active chat</h2>
2727
<p class="you">Bob: Cool, where can I learn more?</p>
2828
</div>
2929
<form>
30-
<input type="text" aria-label="Enter your chat message here" required autofocus>
30+
<input type="text" aria-label="Enter your chat message here" autofocus>
3131
<button>Send</button>
3232
</form>
3333
</section>

overscroll-behavior/main.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ messages.scrollTop = messages.scrollHeight;
2222
form.addEventListener('submit', e => {
2323
e.preventDefault();
2424

25-
let pElem = document.createElement('p');
26-
pElem.setAttribute('class', 'me');
27-
pElem.textContent = 'Chris: ' + input.value;
25+
if(input.value !== '') {
26+
let pElem = document.createElement('p');
27+
pElem.setAttribute('class', 'me');
28+
pElem.textContent = 'Chris: ' + input.value;
2829

29-
messages.appendChild(pElem);
30-
messages.scrollTop = messages.scrollHeight;
30+
messages.appendChild(pElem);
31+
messages.scrollTop = messages.scrollHeight;
3132

32-
input.value = '';
33-
input.focus();
33+
input.value = '';
34+
input.focus();
35+
}
3436
});

0 commit comments

Comments
 (0)