browserquest/BrowserQuest — pull request #123 by sergkr (2013-09-01 22:20:46+00:00)
Title: Fix for issue 104 (allow Enter key to log in), and maybe a partial fix for 116 (warn about mismatched passwords)

The enter key now allows launching the game if the form is filled out. If any fields are missing, then the enter key instead switches focus to the first missing field. This behavior is defined in app.js in a new function called handleEnter.

I refactored some of the game startup logic to remove code duplication. There used to be separate event handlers for each form field in main.js, and the code for them was very similar (reading out the other form fields, checking that they're filled out, and if so then calling app.tryStartGame). Rather than having each of these event handlers doing the same thing, I just moved the shared logic into tryStartGame instead, so it is now responsible for reading out the form fields and performing some basic validation on them.

The validation is done in a new function called validateFormFields in app.js. While I was doing this part, I decided to throw in some basic email validation, and at least a partial fix for issue 116 as well (notify user if passwords do not match). I'm calling it a 'partial' fix since ideally we would do something a little more elegant than an alert box (or maybe this is fine?). Let me know if you'd like me to merge out the fix for 116 into a separate pull request, but I figured it was simple enough to include here while I'm working on that part of the code anyway.

I'm not too certain about the email part - it doesn't look like we actually use the email for anything, so I'm not treating it as required (you can still create a new character without filling in an email). However, if there is *something* in the email field, then the code checks to make sure that it at least *looks* like an email (using a regex I borrowed from a StackOverflow post). This is not true email validation, but it's probably better than nothing it all. Let me know if you prefer I just yank this part out.

Let me know what you think, or if you have any suggestions or questions about what I'm doing.

Thanks,
Sergey