fix for this error: Uncaught TypeError: Cannot call method 'valid' of undefined