Kendo Validator - Focus on first invalid field

1 Answer 93 Views
TextBox Validation
Kevin
Top achievements
Rank 1
Kevin asked on 07 Dec 2021, 12:21 AM

This has been asked before here: https://www.telerik.com/forums/kendo-validator---focus-on-first-invalid-field

However, the given solution does not work with a kendoTextBox. 

If you use the example given in the previous post (http://dojo.telerik.com/ukoLUJ/4?_ga=2.193348590.2100086651.1638809904-402941789.1637689930) and replace the inputs with kendoTextBoxes and update the libraries to the latest version, they will not gain focus when invalid.

Any help would be appreciated, thanks,

Kevin

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 09 Dec 2021, 02:39 PM

Hello, Kevin,

The TextBox is not being focused because the input with k-invalid class is placed within a span that has the same class. As the :first selector is applied, the span is focused instead of the input field. To fix it, modify the selector as follows:

var validator = $("#ticketsForm").kendoValidator({
            validate: function(){
              $("input.k-invalid:first").focus();
            }
          }).data("kendoValidator"),

Here is the modified example for reference as well.

Let me know if you have any further questions.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TextBox Validation
Asked by
Kevin
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or