Closed ggabrakadabra closed 7 years ago
Good issue! Is there a successful request being made for the searched picture? If not, what's the error? If yes, can you look at the data you're sending with the request? What does it look like?
Searched picture returns fine and the title, description, etc for that picture gets put into the input fields. That's why this is strange. But when I click save to favorites, it used to refresh but now it just goes back to the top of the page and it doesn't even run through the function for adding the favorite.
I'm not really following. When you click save to favorites, is the api request made? Does it refresh the page? I'm confused.
Sorry, it's kind of hard to explain. But I'll try to be more clear.
So, when a user clicks on the APOD tab, the astro pic of the day displays. When they click save favorite it will save that picture. But the user can also search for a different APOD by date, and that will show up on the page as well and the corresponding info for it will fill the input fields, but when I click on save favorite after searching for a different picture, it does not work
Ok so I just figured it out lol
So, I on the original function for searching APOD I have
$('.add-picture').on('submit', function (event) {
if (event && event.preventDefault) {
event.preventDefault()
}
const data = getFormFields(event.target)
console.log('favortie picture data is', data)
api.createPictures(data)
.then(api.addToFavoritesList)
.then(api.addToFavoritesList)
.then(ui.addPictureToFavorites)
.fail(ui.addFavoriteFail)
})
but I also have another function that searches by date, and I needed to add the save favorite function to that one too
Why is .then(api.addToFavoritesList)
called twice?
Adding picture only works for the picture of the day and not after searching the other pictures.
This is my show APOD function
This is the handlebars file.
This is my html for the APOD
I just want the user to save any picture fro the database without having to check each day to see the updated picture. And adding the original picture of the day works. Just not the searched picture. But, when the user searches for a different picture, the input fields for adding the picture contain the information about the searched picture. So I'm not sure why this isn't working.