开发者

asp.net mvc 2 validating text inputs on modal windows

i am tasked with the job of creating client-side validation on a form in an asp.net MVC 2 application, which has a modal window (the modal exists as part of the wrapping form, it is not a form unto itself). how would i go about providing validation for these text field inputs while the modal is visible, but do not validate while the modal is not displayed (as to not cause problems in the rest of the form if the modal window is never required)

What is the best approach to achieve this function开发者_运维问答ality?

thanks, Nick


If you're using the jQuery validation plugin (unclear from your tags), just give it a dependency expression that includes :visible on required, like this:

$("form").validate({
  rules: {
    formFieldName: { required: "#formFieldID:visible" }
  }
});


Flag the fields for validation when you load the form. When the window displays flag the forms for validation when it is hidden deflag them.

Or have an array of the fields to be validated and add the fields from the window to this when it is displayed and remove them when it is not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜