Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight which input is left blank #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ form#login-form{

table {
background-color: white;
}

input.invalid {
border: 1px solid red;
}
57 changes: 39 additions & 18 deletions js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ $(document).ready(function(){
var send_flag = true,
row_count = 1,
day_count = 0,
temp_row = [];
temp_row = [],
invalids = [];

// iterates over all the periods
// it goes Monday 1st period to Monday 10th period, then Tuesday and so on
Expand All @@ -189,8 +190,11 @@ $(document).ready(function(){
value = selected_div.children('select').val().toLowerCase(),
temp_object = {},

e$ = function(selector) {
return selected_div.find("input[placeholder='" + selector + "']");
};
f$ = function(selector) {
return selected_div.find("input[placeholder='" + selector + "']").val();
return e$(selector).val();
};

temp_object.value = value.replace(/(<([^>]+)>)/ig,"");
Expand All @@ -216,29 +220,46 @@ $(document).ready(function(){
switch(value){
// there is only one prof and one room
case "theory" :
temp_object.subject = f$('subject');
temp_object.prof = f$('professor code');
temp_object.room = f$('room');;

if(temp_object.room == '' || temp_object.prof == '' || temp_object.subject == ''){
send_flag = false;

var map = {subject: "subject", prof: "professor code", room: "room"};
for (var field in map) {
temp_object[field] = f$(map[field]);
if (temp_object[field] == '') {
send_flag = false;
e$(map[field]).addClass('invalid');
if (invalids.indexOf() == -1) {
invalids.push(map[field]);
}
} else {
e$(map[field]).removeClass('invalid');
}
}

break;

// there are 2 subjects, 2 profs and 2 rooms
// subject is to entered in the single field only as (subj1 + subj2)
case "lab" :
temp_object.subject = f$('subject');
temp_object.prof_FH = f$('professor FH');
temp_object.room_FH = f$('room FH');
temp_object.prof_SH = f$('professor SH');
temp_object.room_SH = f$('room SH');

if(temp_object.subject == '' || temp_object.prof_FH == '' || temp_object.room_FH == '' || temp_object.prof_SH == '' || temp_object.room_SH == '')
send_flag = false;

var map = {
subject: "subject",
prof_FH: "professor FH",
room_FH: "room FH",
prof_SH: "professor SH",
room_SH: "room SH"
};
for (var field in map) {
temp_object[field] = f$(map[field]);
if (temp_object[field] == '') {
send_flag = false;
e$(map[field]).addClass('invalid');
if (invalids.indexOf() == -1) {
invalids.push(map[field]);
}
} else {
e$(map[field]).removeClass('invalid');
}
}

break;

// simple things
Expand All @@ -259,7 +280,7 @@ $(document).ready(function(){

// if there is some field which is left blank "send_flag" would be set to false
if(!send_flag){
alert("Fields not complete");
alert("Fields not complete: " + invalids.join(", "));
} else {
sendData(sendJSON);
}
Expand Down