How to remove client-side validators by default?

I implemented the DateTime dropdown and validation based on the accepted answer in the following section: How to validate the date using 3 drop-down lists (day, month, year) using unobtrusive jquery validation?

I am using MVC 4.

This date with three drop-down lists works fine basically, but sometimes when I click on these three drop-down lists and select different values ​​(including “unselected” values), I get a default error message form. Validation DateTime. Field. Date of birth should be Date. "Even if I chose a valid year / month / date and my custom validator passes.

This message does not prevent POSTing forms when the date is set correctly, but the message is confusing for users.

When I check the unobtrusive rules in Firebug, I see that this message comes by default by default. I know that I can use the rules (“delete” (or delete the rule, message) to delete this default date rule, but I'm not sure when it is time to delete them to stop adding this MVC rule again.

How to remove this default “date” rule to ensure that only my custom rule is valid for these three drop-down lists?

0
source share
2 answers

, , -, ClientDataTypeModelValidatorProvider. . ModelValidatorProvidersCollection Global.asax.cs.

  var clientDataTypeProvider = ModelValidatorProviders.Providers.FirstOrDefault(p => p.GetType().Equals(typeof(ClientDataTypeModelValidatorProvider)));
  ModelValidatorProviders.Providers.Remove(clientDataTypeProvider);

. , number. - ClientDataTypeModelValidatorProvider . - .

+1

, , , - - :

function removeDefaultDateValidators(selector, validatorToRemove) {
    $('form').each(function () {
        var settings = $(this).validate().settings;
        $(selector, this).each(function () {
            // rules and messages seem to be keyed by element name, not id
            var elmName = $(this).attr('name');
            delete settings.rules[elmName][validatorToRemove];
            delete settings.messages[elmName][validatorToRemove];
        });
    });
}

$(function () {
    removeDefaultDateValidators('select[data-val-trippleddldate]', 'date');
});

, , . , trippleddldate.

Firefox IE 9, " ".

0

All Articles