Closed ryanwk closed 7 years ago
I've pushed my code and deployed so that anyone can try it out and see what I'm experiencing
Take a closer look here:
exerciseApi.updateWeightRequest(userInput, id)
.then(function () {
exerciseUi.updateWeightSuccess
onShowAllExercisesSubmit()
})
.catch(exerciseUi.updateWeightFailure)
The line exerciseUi.updateWeightSuccess
is a reference to a function, not a function call. That would be correct if you were just passing it into a .then()
, but you're not, you're creating an anonymous function inside the .then()
. That means that exerciseUi.updateWeightSuccess
is never firing.
I think there's a few other problems that are making this more difficult to debug, as well. You reference exerciseUi.removeExerciseSuccess
but you don't have a function with that name. Also, be careful about relying on event.target
for click events, it's not always what you might think it is. Try logging it.
1) you're in to something with the idea of adding logs in the chain so you can see it yourself 2) Caleb is absolutely right 3) the best way to do this is with subsequent .then()s instead of putting both functions in the same block
fixed this by following Caleb's recommendations:
.then(exerciseUi.updateWeightSuccess)
and adding this to the icon tags within my update button in handlebars:
data-id="{{exercise.id}}"
I'm using a data table. Buttons are added to each record on each successful crud action via subsequent event handlers (exerciseEvents.js & exerciseUi.js) It seems like jQuery is not attaching the event listener to my button when my datatable refreshes.
To clarify, my crud actions (update weight, remove exercise, add exercise, show all exercises) all work. However, after an exercise has been updated or removed from a single record within my datatable, and a user tries to use either the update or remove buttons of a different record, then things fall apart. The id for other records become undefined and I think jQuery is no longer attaching event listeners to the specified buttons that populate on each record within my datatable. However, sometimes you can add an exercise and things work normally again. Strange.
Due to this, I am not able to grab the id of a record utilizing this bit of jQuery:
My inability to grab the id of a record does not allow me to delete or update a record. The simple solution is and was to have a user input the id manually but I want this operation to be implicit. I also think, my trouble with jQuery here, is also why I can't hide my update and add exercise modals. Although, that might be an unrelated issue. For now the focus is on how to get my update and delete buttons working properly from within my datatable.
The datatable is created through this mechanism:
and then it is 'refreshed' by calling
showExerciseList(data)
from inside each successful event function (from within exerciseUi.js). Here's an example:I feel like the crux of my problems stems from how I'm using jQuery.
I read up on dynamic content and jQuery, specifically delegated events: http://api.jquery.com/on/#direct-and-delegated-events Then read up on this issue on stackover flow. Tried the solution, no luck. https://stackoverflow.com/questions/15090942/event-handler-not-working-on-dynamic-content
I'm unsure of when and where I should place jQuery in order for my update and delete buttons to work properly. I'm preparing to methodically stick logs in everywhere and map the chain of events.
I need help organizing and structuring my event handling/success functions with jQuery, so that my delete and update buttons grab the id of a record within my data table, and enables my delete and update buttons to perform their respective operations.
events:
ui:
delete button (inside handlebars):
update weight button (inside handlebars):
update exercise modal body (lives in index.html):
datatable (lives in index.html)
Please help. The issue outlined above and getting my modals to close are the last things that I need to fix in order to resubmit.
@jordanallain @MicFin @tvlangley @payne-chris-r @sdavidson140 @Jcornmanhomonoff @bengitscode @benjimelito