-
Notifications
You must be signed in to change notification settings - Fork 0
/
editgroupvalidation.js
53 lines (35 loc) · 1.52 KB
/
editgroupvalidation.js
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
51
52
53
let doneButton = document.querySelector("#done-button");
let groupIDP = document.querySelector("#group-id-paragraph");
console.log(groupIDP);
let groupID = groupIDP.innerText;
doneButton.addEventListener("click", function () {
window.location.href = "groupprofile.php?groupid=" + groupID;
});
//client validations
let editForm = document.querySelector("#edit-form");
let groupNameField = editForm.elements.groupname;
let groupDescField = editForm.elements.desc;
let groupNameError = document.querySelector("#groupname-error");
let descriptionError = document.querySelector("#description-error");
editForm.addEventListener('submit', function (eventObj) {
let newGroupName = groupNameField.value;
let newDescription = groupDescField.value;
//check group name
if (newGroupName.length < 4) {
eventObj.preventDefault();
groupNameError.innerText = "Group Name Length Has To Be Atleast 4 Characters";
}
//check description
if (newDescription.length < 15) {
eventObj.preventDefault();
descriptionError.innerText = "Description Length Has To Be Atleast 15 Characters";
}
});
groupNameField.addEventListener("input", function () {
let newGroupName = groupNameField.value;
if (newGroupName.length >= 4) { groupNameError.innerText = ""; }
});
groupDescField.addEventListener("input", function () {
let newDescription = groupDescField.value;
if (newDescription.length >= 15) { descriptionError.innerText = ""; }
});