Conversation
BackTREKWhat We're Looking For
|
| }); | ||
| ['name', 'continent', 'category', 'weeks', 'cost'].forEach((field) => { | ||
| if (attr[field] === '') { | ||
| errors[field] = "can't be blank"; |
There was a problem hiding this comment.
I would suggest also adding an if statement like
if (errors[field]) {
errors[field].push('can't be blank');
} else {
errors[field] = ['can't be blank'];
}
That way you can have multiple errors for a field.
| if (parseFloat(attr[field]) === NaN) { | ||
| errors[field] = "must be a number"; | ||
| } | ||
| if (!parseFloat(attr[field]) > 0) { |
| if (object.isValid()) { | ||
| object.save({}, { | ||
| success: (response) => { | ||
| formSuccess(type, form) |
There was a problem hiding this comment.
Note, for trips, this won't allow a newly created trip to show up in a displayed list. The user would have to refresh the browser to see it.
On a successful trip save, you should execute a tripList.fetch();. That would trigger render because it's listening for an update event.
I do however really like how you abstracted out the saveIfValid function so it works for all your models. Nice!
| $('#intro-button').on('click', (e) => { | ||
| $('#intro-button').hide(200); | ||
| $('#loading').show(500); | ||
| tripList.fetch({ |
There was a problem hiding this comment.
You should also have an error callback, just in case the API is down to alert the user.
| let field = targetElement[0].id; | ||
| tripList.comparator = field; | ||
| targetElement.addClass('current-sort'); | ||
| tripList.sort(); |
There was a problem hiding this comment.
It's better stylistically to have render listening for a sort event.
So adding tripList.on('sort', render);
BackTREK
Congratulations! You're submitting your assignment!
Comprehension Questions