-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
50 lines (42 loc) · 1.42 KB
/
validate.js
File metadata and controls
50 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
console.log("greenhouse validator in The House!");
const textAreas = document.getElementsByTagName('textarea');
const submitButton = document.getElementById('submit_scorecard_button');
function isFeedbackLongEnough(text) {
const pattern = /\.\s/g;
// Likely to be one off since it won't match the last sentence.
const minNumSentences = ((text || '').match(pattern) || []).length;
return minNumSentences >= 4;
}
function validateAndStylePage() {
let readyToSubmit = true;
for (let i = 0, l = textAreas.length; i < l; i++) {
const area = textAreas[i];
if (area.id === "scorecard_public_notes") {
// The "Notes for other interviewers section" should be as long or short as the interviewer deems necessary.
continue;
}
const text = area.value;
if (!isFeedbackLongEnough(text)) {
area.style.borderColor = "red";
document.body.style.backgroundColor="#c7f3f1";
readyToSubmit = false;
} else {
area.style.borderColor = "green";
}
}
if (readyToSubmit) {
submitButton.style.pointerEvents = "";
submitButton.style.color = "green";
document.body.style.backgroundColor="#f3f3f3";
} else {
submitButton.style.pointerEvents = "none";
submitButton.style.color = "red";
}
}
for (let i = 0, l = textAreas.length; i < l; i++) {
const area = textAreas[i];
area.onkeyup = validateAndStylePage;
area.onblur = validateAndStylePage;
area.onchange = validateAndStylePage;
}
validateAndStylePage();