-1

I am validating an HTML using knockout-validation, I need to focus the cursor on the first control having error how could I do that?

Please help..

Thanks

1
  • I've attempted to answer but it's a bit tricky to know what you may have tried already unsuccessfully if you don't add that info to the question. Commented Apr 10, 2014 at 11:56

1 Answer 1

3

Make sure you are setting an error class for your elements in the data-bind attrbute of all elements being validated:

data-bind = " ...
              validationOptions: { errorElementClass: 'input-validation-error' }
              ... "

Then at the point of validation you can get all of these elements with jquery and just apply focus to the first one:

$(".input-validation-error").first().focus();

Not the answer you're looking for? Browse other questions tagged or ask your own question.