0

After the validation fails ( if input is empty) for POST form, the cursor is set on the first input that has failed and the validation styling disappears:

enter image description here

I tried using jquery functions like .blur() or .focusout() after Login button is clicked, but it did not work.

Any suggestions how to remove the cursor from any text fields after POST validation fails?

Irmantas Želionis
  • 2,194
  • 3
  • 17
  • 30
  • Your question states asp.net, but your tags are for MVC - if it's asp.net, then use `SetFocusOnError="false"` from this answer https://stackoverflow.com/questions/41428936/asp-net-auto-focus-of-required-field-validator-is-not-working-in-safari – freedomn-m Mar 04 '19 at 17:50
  • Just a thought, but have you tried adding a callback that is used when the function from the controller returns an error? Some snippets of code might help (something like the form and what it's using to make the POST, and what you've tried using for addressing the problem). – Dortimer Mar 04 '19 at 17:52
  • 1
    If you're POSTing the form, then bluring the button would have no effect as that instance will no longer exist as the page is re-rendered with new HTML. – freedomn-m Mar 04 '19 at 17:52
  • Alternatively: `$(function() { if (document.activeElement != document.body) document.activeElement.blur(); });` from here: https://stackoverflow.com/a/21551843/2181514 – freedomn-m Mar 04 '19 at 17:55
  • There's probably a way to configure the validator not to do this though (ie do it properly) – freedomn-m Mar 04 '19 at 17:55

1 Answers1

0

would this work?

 $('form').submit(function () {
                if (!$('form').valid()) {
                    $('input').blur();
                }         
            });
Bryan Dellinger
  • 4,724
  • 7
  • 33
  • 79