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

Clarified Form Validation for Instructors on the SLC Page #1383

Open
wants to merge 2 commits into
base: development
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
10 changes: 10 additions & 0 deletions app/static/js/instructorTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function createNewRow(selectedInstructor) {
let editLink = newRow.find("td:eq(0) a")
editLink.attr("id", `editButton-${username}`);

newRow.attr("data-username", username)
editLink.attr("data-username", username)
newRow.prop("hidden", false);
lastRow.after(newRow);
Expand All @@ -43,9 +44,18 @@ export function createNewRow(selectedInstructor) {
}

$("#instructorTableNames").append(`<input hidden name="instructor[]" value="${username}"/>`)
updateEmptyTableMessage()
}

export function getCourseInstructors() {
// get usernames out of the table rows
return $("#instructorTableNames input").map((i,el) => $(el).val())
}

export function updateEmptyTableMessage(){
if ($("#instructorTable tbody tr").length > 2){
$("#instructorTable tbody tr").first().attr("hidden", true)
} else{
$("#instructorTable tbody tr").first().attr("hidden", false)
}
}
3 changes: 2 additions & 1 deletion app/static/js/searchUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function searchUser(inputId, callback, clear=false, parentElement
}

return false;
}
},
autoFocus: true
});
};
32 changes: 24 additions & 8 deletions app/static/js/slcNewProposal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getCourseInstructors, getRowUsername, createNewRow} from './instructorTable.js'
import {getCourseInstructors, getRowUsername, createNewRow, updateEmptyTableMessage} from './instructorTable.js'
import searchUser from './searchUser.js'

var currentTab = 0; // Current tab is set to be the first tab (0)
Expand Down Expand Up @@ -130,17 +130,31 @@ $(document).ready(function(e) {
$("#instructorTable").on("click", ".removeButton", function() {
let closestRow = $(this).closest("tr");
let username = closestRow.data('username');

// Check if the username is not empty or undefined
if (username) {
$("#instructorTableNames input[value='" + username + "']").remove();
closestRow.remove();
}
});
updateEmptyTableMessage();
});

$("#courseInstructor").on("focusout", function(){
$("#courseInstructor").val("")
})

$("#courseInstructor").on('input', function() {
searchUser("courseInstructor", createNewRow, true, null, "instructor");
});
$("#courseInstructor").on('input', function() {
searchUser("courseInstructor", createNewRow, true, null, "instructor");
});

$("#courseInstructor").popover({
trigger: "hover",
sanitize: false,
html: true,
content: function() {
return $(this).data('tooltip');
}
});

// for each row in instructorTable that has an instructor, pass that instructors phone data to setupPhoneNumber
$('#instructorTable tr').each(function(){
Expand Down Expand Up @@ -306,9 +320,11 @@ function validateForm() {
var instructors = getCourseInstructors()
if (!instructors.length && currentTab == 1) {
valid = false;
$("#courseInstructor").addClass("invalid");
$("#instructorTable .emptyTableMessage").addClass("table-danger");
$("#instructorTable .emptyTableMessage label").removeClass("text-secondary");
} else {
$("#courseInstructor").removeClass("invalid");
$("#instructorTable .emptyTableMessage").removeClass("table-danger");
$("#instructorTable .emptyTableMessage label").addClass("text-secondary");
}

if (valid) {
Expand Down
16 changes: 8 additions & 8 deletions app/templates/serviceLearning/slcProposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ <h3 class="text-center pb-4">Status:
class="form-control"
type="search"
placeholder="Search instructor"
data-tooltip="Click on an instructor to add them"
value="" />
<table
class="table mb-3"
class="table mb-1"
id="instructorTable"
name="instructorTable">
<thead>
<tr>
<th scope="col">Instructor</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr class="emptyTableMessage" {{"hidden" if courseInstructor else ""}}>
<td>
<label class="text-secondary ms-1"><i>No instructors selected</i></label>
</td>
<td></td>
</tr>
<tr data-username="" hidden>
<td>
<p class="mb-0"></p>
Expand All @@ -51,7 +52,6 @@ <h3 class="text-center pb-4">Status:
</tr>
{% endfor %}
</tbody>

</table>
<div id='instructorTableNames'>
{% for instructor in courseInstructor %}
Expand Down
Loading