Autofocus on validation error

I need to set autofocus to the first error field after validation failed. What is the best way to achieve this?
Was this page helpful?