Now, it’s time to give the user the ability to delete a line. First, I created a button for the user to click to delete a line. I added some basic CSS for a minimal look, and used the ✖ character for an even “✖”.
And the css:
This created a nice, minimalist delete button.
Now, I added the code for what would happen when the button was clicked. I decided to use a confirm()
method in the javascript, in order to keep things simple for now. Might come back in the future to make it look a bit more fancy.
This script binds an on('click')
event to each delete button. When clicked, it prompts the user to make sure they want to delete the button. If they do, the script takes the line’s hex_id
from the id
of the button and sends an ajax request to my as yet-uncreated route '/line/delete'
. Should this route execute properly, the checkbox and the line corresponding to the list item are found with the same hex_id
and removed. This essentially functions the same way my checkbox functions, and I benefited significantly from the fact that I already had this architecture in place.
Now, onto the route.
The route again takes its queues almost entirely from the '/line/checked'
route. It finds the line by the provided hex_id
and then deletes it. Assuming this was successful, it returns the line’s hex_id
so that the client can use it to delete the line.
Pretty simple stuff, and it all works. This is a short post today, but I wanted to get it out, and honestly it’s really refreshing to be able to implement a feature so cleanly and with so little hassle. I’m hopeful that this shows both a) that I’m improving in my skills, and b) that I’ve constructed a strong architecture for the program.
Next Steps:
- move list items around
- access recipe if gotten from url