CIS 658 |
Javascript |
Winter 2020 |
You may work in pairs on this assignment.
Part 1: Client-side Error Checking
Add client-side error checking to your either the Bugs or Authors page of your bug tracking app (both "new" and "edit").
- Add input and/or change listeners to the fields and report errors as soon as they are made.
- The submit button should be disabled whenever a form field is in an invalid state.
Make sure the error messages are nicely formatted. (Don't just throw a string up on the screen.)
You must write your own JavaScript. Don't use the built-in client-side form validation for this assignment.
Part 2: Client-side Table Sorting
Add Javascript to your bugs listing (the "index" route) that will respond to a click on a table headding by sorting the table according to that column. Here is one possible approach:
- Add a click listener to each
th
element. - When a header is clicked
- Get the
tbody
element and save it in a variable namedtbody
- Call
tbody.getElementsByTagName('tr')
on thetbody
element to get all thetr
elements inside thetbody
. (Notice that callingdocument.getElementsByTagName('tr')
will return alltr
elements in the document, which is not what you want.) - Use a loop to copy all
tr
elements to a different array. - Use a separate loop to remove all the
tr
elements from thetbody
- It is important to use two separate loops. (Bad things may happen if you remove elements from a loop while iterating through it.)
- You can use the method
tbody.removeChild
to remove elements from the DOM.
- Use the Array
sort
method to sort thetr
objects according to the desired column. (Use the comparison callback to compare the rows by column.) - Re-insert the sorted elements into the
tbody
element. (Use theappendChild
method.)
- Get the
Deliverables:
Updated Thursday, 20 February 2020, 4:48 PM