Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrice Roberts
22,415 PointsWould it not be simpler to call ".focusout()", instead of ".keyup"?
In the example in this lesson, Chalkers uses "focus" to define the first event, and then ".keyup" to trigger the second event.
For a better UX, would it be best practice to bind the event that checks the password for 8 characters, after the user has clicked out of it, so that the button event wouldn't trigger while the user is still typing?
Brice Roberts
22,415 PointsThank you. Yes, I guess I didn't clarify as well I should have. I knew the exercise is just proof of concept, so it was more of an internal problem solving question.
I wasn't sure if there was a real world benefit to splitting the event as shown.
Jordan Hoover
Python Web Development Techdegree Graduate 59,268 PointsYeah, I don't know too much about UX, but I've seen it done both ways.
2 Answers
Steven Parker
231,275 PointsI think the whole point is to trigger during typing to give the user immediate feedback once the criteria have been satisfied (or if a change causes them to not be again).
Brice Roberts
22,415 PointsYeah. I was just brainstorming other ways to complete the task. His is pretty straight forward, I was just trying to think outside the example.
Adrien Contee
4,875 PointsTrue you could use the focusOut() method but if the user went back and continued typing even passed 8 characters the pop up would still be visible... you would still need to bind a key up event. I think AC wanted to display how statement chaining could be used on events and I'm pretty sure AC will introduce the on() method really soon if not in the next video. But that's what i used.
$("form span").hide();
$("#password").on("focus keyup", passwordCheck);
function passwordCheck() {
if ($(this).val().length > 8) {
$(this).next().hide();
} else {
$(this).next().show();
}
}
Jordan Hoover
Python Web Development Techdegree Graduate 59,268 PointsJordan Hoover
Python Web Development Techdegree Graduate 59,268 PointsYou mean reduce the two events to just one focusout event? I suppose that would depend on your preferences, but I think he was trying to show how multiple events could be bound/triggered.