Skip to content

Commit 7c9f8cf

Browse files
committed
css fixes and js fixes to tags
1 parent 62d6d48 commit 7c9f8cf

File tree

2 files changed

+66
-52
lines changed

2 files changed

+66
-52
lines changed

frontend/javascript/modules/majorProjectForm.js

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,59 @@ import FetchUtil from "../utils/fetchUtil";
22

33
export default class MajorProjectForm {
44

5-
tags_written = false;
6-
7-
constructor(form) {
8-
this.form = form;
9-
this.endpoint = '/major_project/submit';
10-
this.render();
11-
}
12-
13-
render() {
14-
this.form.querySelector('input[type=submit]')
15-
.addEventListener('click', e => this._submitForm(e));
16-
this.form.querySelector('input[id=skill-input]')
17-
.addEventListener('focusout', e => this.onWriteSkill(e));
18-
}
19-
20-
onWriteSkill(e) {
21-
let input = document.getElementById("skill-input")
22-
if (!this.tags_written) {
23-
this.tags_written = true
24-
document.getElementsByClassName("placeholder").item(0).remove()
5+
6+
constructor(form) {
7+
this.form = form;
8+
this.endpoint = '/major_project/submit';
9+
this.tags_written = false;
10+
this.tag_keys = ["Enter", "Comma", "Tab"];
11+
this.render();
12+
}
13+
14+
render() {
15+
this.form.querySelector('input[type=submit]')
16+
.addEventListener('click', e => this._submitForm(e));
17+
this.form.querySelector('input[id=skill-input]')
18+
.addEventListener('focusout', e => this.onWriteSkill(e));
19+
this.form.querySelector('input[id=skill-input]')
20+
.addEventListener('keyup', e => this.onKeyPress(e));
21+
}
22+
23+
onKeyPress(e) {
24+
if (this.tag_keys.includes(e.code)) {
25+
e.preventDefault();
26+
this.onWriteSkill(e);
27+
}
2528
}
29+
30+
onWriteSkill(e) {
31+
let input = document.getElementById("skill-input")
32+
if (!this.tags_written) {
33+
this.tags_written = true
34+
document.getElementsByClassName("placeholder").item(0).remove()
35+
}
2636
let txt = input.value.replace(/[^a-zA-Z0-9\+\-\.\# ]/g, ''); // allowed characters list
27-
if (txt) input.insertAdjacentHTML("beforebegin", '<span class="skill-tag">' + txt + '</span>');
28-
input.value = "";
29-
input.focus();
30-
31-
}
32-
33-
_submitForm(e) {
34-
e.preventDefault();
35-
36-
let payload = {
37-
projectName: this.form.querySelector('input[name=name]').value,
38-
projectTldr: this.form.querySelector('input[name=tldr]').value,
39-
projectTimeSpent: this.form.querySelector('textarea[name=time-commitment]').value,
40-
projectDescription:
41-
this.form.querySelector('textarea[name=description]').value
42-
};
43-
44-
FetchUtil.postWithWarning(this.endpoint, payload, {
45-
warningText: "You will not be able to edit your " +
46-
"project once it has been submitted.",
47-
successText: "Your project has been submitted."
48-
});
49-
}
37+
if (txt) input.insertAdjacentHTML("beforebegin", '<span class="skill-tag">' + txt + '</span>');
38+
input.value = "";
39+
input.focus();
40+
41+
}
42+
43+
_submitForm(e) {
44+
e.preventDefault();
45+
46+
let payload = {
47+
projectName: this.form.querySelector('input[name=name]').value,
48+
projectTldr: this.form.querySelector('input[name=tldr]').value,
49+
projectTimeSpent: this.form.querySelector('textarea[name=time-commitment]').value,
50+
projectDescription:
51+
this.form.querySelector('textarea[name=description]').value
52+
};
53+
54+
FetchUtil.postWithWarning(this.endpoint, payload, {
55+
warningText: "You will not be able to edit your " +
56+
"project once it has been submitted.",
57+
successText: "Your project has been submitted."
58+
});
59+
}
5060
}

frontend/stylesheets/pages/_major-project.scss

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,29 @@
1313
}
1414

1515
.form-skilltags {
16-
display: block;
16+
box-shadow: inset 0 -1px 0 #ddd;
17+
border: none;
18+
padding: 0;
19+
}
20+
21+
.placeholder {
22+
color: #bbb;
23+
font-size: 16px;
24+
}
25+
26+
.skill-tag {
27+
display: block;
1728
float: left;
1829
background: #d979e3;
1930
padding: 5px 10px;
20-
box-shadow: inset 0 -1px 0 #ddd;
21-
border: none;
2231
}
2332

24-
.form-skilltags:after {
33+
.skill-tag:after {
2534
position: absolute;
2635
content: "×";
2736
border: 1px solid;
2837
border-radius: 10px;
2938
padding: 0 4px;
3039
margin: 3px 0 10px 7px;
3140
font-size: 10px;
32-
}
33-
34-
.placeholder {
35-
color: #bbb;
36-
font-size: 16px;
3741
}

0 commit comments

Comments
 (0)