Ignore non visible fields from JQuery Validation / ASP.NET MVC fluent validation



The JQuery Validation plugin is quite a smart tool to check the data consistency on client side but might need some extra tweaking to work as expected. Depending on the settings and version, it might not want to ignore the fields that are non-visible, like like a text box placed on a hidden DIV, even though it would ignore any field that is disabled itself.

The JQuery Validation plugin version that comes with ASP.NET MVC 3 (v1.8) will not ignore non-visible inputs. To change the settings and ignore every control that is placed somewhere within a hidden DIV, use the following simple script:


$(function () {
$('form').validate().settings.ignore = 'div:hidden *';
});


To ignore everything that is not visible, no matter what the hierarchy is, use simply (the current version, v1.9 uses this as a default):


$(function () {
$('form').validate().settings.ignore = ':hidden';
});


Comments

  1. I have come to understand that developing and using JQuery Validation plug-ins in ASP.NET can let you concentrate on what exactly is important instead of getting captured up in the facts.

    ReplyDelete

Post a Comment

Popular posts from this blog

MurMurHash3, an ultra fast hash algorithm for C# / .NET

Removing Malware and Bloatware from Lenovo K3 Note (K50-T5)

Quick select algorithm - find the Kth element in a list in linear time