TIP: Validating a field

When you validate a field you might do that via the onDataChange event like I did. But imagine this with my previous email validation example in mind:

  • you input an email address or a string of addresses.
  • there is a mistake in the field and you get an error message
  • the method forces you back into the field
  • you now into the field or place your cursor in another field

RESULT

  • nothing changed so you DON’T trigger the onDataChange event!

SOLUTION

  • trigger the method via onFocusLost. This will ALWAYS validate the field. The simple method won’t slow down noticeable…