Checking and unchecking an Item

The last feature missing from the web app is the ability to check and uncheck an item such that its state is saved on the server. This is easily achieved by setting up a change event listener on the input checkbox, and upon check and unchecking, it will trigger the callback function. We extract the checkbox from the event and get the checked state and make a PATCH request to our API on the item's endpoint. Upon success, we will need to do nothing, but if there is an error, we show the error message in the form of an alert dialog and revert the checkbox state so that the user can try again. The following is the code for adding this:

$('body').on('change', 'input[type=checkbox]', function(event) { var checkbox ...

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.