3

Using MicrosoftMvcValidation.js for client side validation, is there an easy way of programatically (in javascript) turning the validation off and on for particular fields?

Is it possible for example to use jquery to bind/unbind the events?

1 Answer 1

2

Imran Baloch's Blog has your answer:

http://weblogs.asp.net/imranbaloch/archive/2010/06/20/disabling-client-side-validation-for-disabled-input-controls-in-asp-net-mvc.aspx

It involves a customization to MicrosoftMvcValidation.debug.js

Change this:

if (!Sys.Mvc._validationUtil.stringIsNullOrEmpty(errorMessage)) {
    Array.add(errors, errorMessage);
}

To this:

var inptEl = $get(context.fieldContext.elements[0].id);
if (!Sys.Mvc._validationUtil.stringIsNullOrEmpty(errorMessage) && !inptEl.disabled) {
    Array.add(errors, errorMessage);
}
else
    Sys.UI.DomElement.removeCssClass(inptEl, Sys.Mvc.FieldContext._inputElementErrorCss);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.