I’m excited to report that a lot of progress was made this week on the project. I spent most of the week working on the EDIT functionality of each of the question types, which involved both backend and frontend development work. Following last week’s work getting the Edit view implemented for True/False questions (but not actually updating anything), I began this week by learning how to implement a POST action of the True / False question controller to handle the updating of the question being updated in the database itself. I then edited the edit view for true / false questions to submit the updated data to the controller action, and was pleased to see everything working! Here is an example of editing a True/False question:
With this accomplishment, I was then able to apply the things I learned to the other question types. I next implemented editing of free-response questions, which ended up being very similar to the True / False questions. Here is an example:
Multiple choice was next, which presented a bit more of a challenge, as I needed to write JS code to execute on load that used the input question data to populate the text fields accompanying each possible answer’s radio button, as well as selecting the previously-chosen answer in the form. This was actually considerably difficult because of differences in how C# and JavaScript work with Model data being used by the view. To obtain a usable JavaScript list of possibleAnswers from the input model required using JavaScript’s JSON.parse() in combination with C#’s Html.Raw() and Json.Serialize() functions to successfully work with the data. Here is an example of editing a multiple choice question:
Finally, the most challenging portion of this week’s work involved implementing the Edit functionality of the Check-All-That-Apply question type, as this question type involves an unbounded number of possible answers that the user can add during question creation. I decided that I needed to implement a “delete possible answer” function, which was not included in the original create question view. This involved writing a considerable amount of JavaScript code to allow for the dynamic addition and deletion of an arbitrary number of possible answers to a particular question, as well as a solution to ensure that the final resulting form, when submitted, has proper incrementing field ids and names so that the controller is able to save the updated question properly. I was able to solve this problem by implementing a function that executes whenever the “Save” button is clicked, that iterates through the table elements, properly setting the field ids and names, before ultimately submitting the data to the controller. Here is an example of editing a Check All That Apply Question:
Anyway, it’s been a lot of work, but I’m proud of the accomplishments I’ve achieved on the project this week. Over the next week, I’ll focus on implementing the DELETE functionality for each question type, as well as tests overall. The midpoint of the project is next week, and I’m feeling confident in our ability to complete the project to specification and on time. I’m also happy to report that our project is now hosted and accessible, and can be checked out here. Until next time…