Hey all,
I’m working through the express app course and have a question about the create book form.
Here’s what’s used on this form in the course:
for author in authors
if book
option(value=author._id selected=(author._id.toString()===book.author._id.toString() ? 'selected' : false) ) #{author.name}
else
option(value=author._id) #{author.name}
It appears that this if/else block is only being used to denote the selected
value when the form is loaded (which shouldn’t impact functionality).
Am I missing something, or is this unnecessary? It seems like if selected
is only being used to select the first author in the list as the default you could use this and get the same result, right?
for author in authors
option(value=author._id) #{author.name}
If you needed a default selected value that would work with the validation measures, could you do this?
option(value="" selected)
for author in authors
option(value=author._id) #{author.name}
Is this so the selection stays the same if the form doesn’t validate? This exercise uses browser validation, so I’m not sure if that would be an issue since the form doesn’t reset if it doesn’t validate.
While I like lightweight code, I don’t want to miss anything that I’m not considering, so I appreciate the feedback.
Thanks