Asp.net mvc 5 使用Jquery步骤向导进行不引人注目的验证

Asp.net mvc 5 使用Jquery步骤向导进行不引人注目的验证,asp.net-mvc-5,jquery-steps,Asp.net Mvc 5,Jquery Steps,最近我问了一个关于如何定制JQuery步骤的问题,因为我想使用局部视图而不是静态内容。我使用jquery步骤支持的以下代码部分解决了这个问题 <h3>Step 1</h3> <section data-mode="async" data-url="/Formation/RenderStep1"></section> <h3>Step 2</h3> <section data-mod

最近我问了一个关于如何定制JQuery步骤的问题,因为我想使用局部视图而不是静态内容。我使用jquery步骤支持的以下代码部分解决了这个问题

   <h3>Step 1</h3>
      <section data-mode="async" data-url="/Formation/RenderStep1"></section>

   <h3>Step 2</h3>
      <section data-mode="async" data-url="/Formation/RenderStep2"></section>
$("#my-steps").steps({
        headerTag: "h3",
        bodyTag: "section",
        contentMode: "async",
        transitionEffect: "fade",
        stepsOrientation: "vertical",

        onStepChanging: function (event, currentIndex, newIndex) {             
            return true;
        }
    });

我尝试调用$.validator.unobtrusive.parse(“#myform”);在onStepChanging函数中,但是(“#myform”)没有定义,我仍然不知道这是否是手动调用不引人注目的验证的正确方法。请指导我,并告诉我实现这一目标的方向。非常感谢您提供的任何帮助。

听起来您好像试图在JQuery步骤库中管理多个表单,我认为这不是它的目的

在配置JQuery步骤时,可以根据视图中的表单进行设置

不引人注目的JQuery验证是查看视图中的模型,并使用相关数据属性自动配置HTML以进行错误处理

此验证应在客户端自动启动

只要在同一表单元素中封装了部分视图,使用部分视图就不会有问题

将每个局部视图包装成自己的形式的要求是什么?如果您试图在整个JQuery步骤表单向导中发表多篇文章,那么您将失败该对象

在JQuery步骤表单的每个步骤中,您只需验证一个表单,如下所示:-

onStepChanging: function (event, currentIndex, newIndex) {

                    //Allways allow user to move backwards.

                    if (currentIndex > newIndex) {
                        return true;
                    }

                    // Remove the validation errors from the next step, incase user has previously visited it.

                    var form = $(this);

                    if (currentIndex < newIndex) {

                        // remove error styles
                        $(".body:eq(" + newIndex + ") label.error", form).remove();
                        $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
                    }

                    //disable validation on fields that are disabled or hidden.

                    form.validate().settings.ignore = ":disabled,:hidden";

                    return form.valid();
                }
JQuery步骤的目的是让用户在填写表单时有一种流畅的体验,并且不会被问到的问题数量所淹没


从开发者的角度来看,它使我们能够将表单拆分为大小合适的块,而不必担心在屏幕之间保存进度或丢失表单数据的状态,并允许我们捕获所有必需的数据,而只需在满足所有验证条件后发布一篇帖子。

听起来像是您在尝试管理多个表单在JQuery步骤库中,我认为这不是它的目的

在配置JQuery步骤时,可以根据视图中的表单进行设置

不引人注目的JQuery验证是查看视图中的模型,并使用相关数据属性自动配置HTML以进行错误处理

此验证应在客户端自动启动

只要在同一表单元素中封装了部分视图,使用部分视图就不会有问题

将每个局部视图包装成自己的形式的要求是什么?如果您试图在整个JQuery步骤表单向导中发表多篇文章,那么您将失败该对象

在JQuery步骤表单的每个步骤中,您只需验证一个表单,如下所示:-

onStepChanging: function (event, currentIndex, newIndex) {

                    //Allways allow user to move backwards.

                    if (currentIndex > newIndex) {
                        return true;
                    }

                    // Remove the validation errors from the next step, incase user has previously visited it.

                    var form = $(this);

                    if (currentIndex < newIndex) {

                        // remove error styles
                        $(".body:eq(" + newIndex + ") label.error", form).remove();
                        $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
                    }

                    //disable validation on fields that are disabled or hidden.

                    form.validate().settings.ignore = ":disabled,:hidden";

                    return form.valid();
                }
JQuery步骤的目的是让用户在填写表单时有一种流畅的体验,并且不会被问到的问题数量所淹没


从开发者的角度来看,它使我们能够将表单拆分为大小合适的块,而不必担心在屏幕之间保存进度或丢失表单数据的状态,并允许我们捕获所有必需的数据,而只需在满足所有验证条件后发布一篇帖子。

听起来像是您在尝试管理多个表单在JQuery步骤库中,我认为这不是它的目的

在配置JQuery步骤时,可以根据视图中的表单进行设置

不引人注目的JQuery验证是查看视图中的模型,并使用相关数据属性自动配置HTML以进行错误处理

此验证应在客户端自动启动

只要在同一表单元素中封装了部分视图,使用部分视图就不会有问题

将每个局部视图包装成自己的形式的要求是什么?如果您试图在整个JQuery步骤表单向导中发表多篇文章,那么您将失败该对象

在JQuery步骤表单的每个步骤中,您只需验证一个表单,如下所示:-

onStepChanging: function (event, currentIndex, newIndex) {

                    //Allways allow user to move backwards.

                    if (currentIndex > newIndex) {
                        return true;
                    }

                    // Remove the validation errors from the next step, incase user has previously visited it.

                    var form = $(this);

                    if (currentIndex < newIndex) {

                        // remove error styles
                        $(".body:eq(" + newIndex + ") label.error", form).remove();
                        $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
                    }

                    //disable validation on fields that are disabled or hidden.

                    form.validate().settings.ignore = ":disabled,:hidden";

                    return form.valid();
                }
JQuery步骤的目的是让用户在填写表单时有一种流畅的体验,并且不会被问到的问题数量所淹没


从开发者的角度来看,它使我们能够将表单拆分为大小合适的块,而不必担心在屏幕之间保存进度或丢失表单数据的状态,并允许我们捕获所有必需的数据,而只需在满足所有验证条件后发布一篇帖子。

听起来像是您在尝试管理多个表单在JQuery步骤库中,我认为这不是它的目的

在配置JQuery步骤时,可以根据视图中的表单进行设置

不引人注目的JQuery验证是查看视图中的模型,并使用相关数据属性自动配置HTML以进行错误处理

此验证应在客户端自动启动

只要在同一表单元素中封装了部分视图,使用部分视图就不会有问题

将每个局部视图包装成自己的形式的要求是什么?如果您试图在整个JQuery步骤表单向导中发表多篇文章,那么您将失败该对象

在JQuery步骤表单的每个步骤中,您只需验证一个表单,如下所示:-

onStepChanging: function (event, currentIndex, newIndex) {

                    //Allways allow user to move backwards.

                    if (currentIndex > newIndex) {
                        return true;
                    }

                    // Remove the validation errors from the next step, incase user has previously visited it.

                    var form = $(this);

                    if (currentIndex < newIndex) {

                        // remove error styles
                        $(".body:eq(" + newIndex + ") label.error", form).remove();
                        $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
                    }

                    //disable validation on fields that are disabled or hidden.

                    form.validate().settings.ignore = ":disabled,:hidden";

                    return form.valid();
                }
JQuery步骤的目的是让用户在填写表单时有一种流畅的体验,并且不会被问到的问题数量所淹没

从开发人员的角度来看,它使我们能够将表单分割成大小合适的块,而不必担心在屏幕之间保存进度或丢失表单数据的状态,并允许我们捕获所有
<script>
## // to adjust step height to fit frame after showing validation messages##
$(document).ready(function() {
  function adjustIframeHeight() {
    var $body   = $('body'),
        $iframe = $body.data('iframe.fv');
    if ($iframe) {
        // Adjust the height of iframe
        $iframe.height($body.height());
    }
}

// IMPORTANT: You must call .steps() before calling .formValidation()
$('#profileForm')
  // setps setup
    .steps({
        headerTag: 'h2',
        bodyTag: 'section',
        onStepChanged: function(e, currentIndex, priorIndex) {
            // You don't need to care about it
            // It is for the specific demo
            adjustIframeHeight();
        },


        // Triggered when clicking the Previous/Next buttons
        // to apply validation to your section 

        onStepChanging: function(e, currentIndex, newIndex) {
            var fv         = $('#profileForm').data('formValidation'), // FormValidation instance
                // The current step container
                $container = $('#profileForm').find('section[data-step="' + currentIndex +'"]');

            // Validate the container
            fv.validateContainer($container);

            var isValidStep = fv.isValidContainer($container);
            if (isValidStep === false || isValidStep === null) {
                // Do not jump to the next step
                return false;
            }

            return true;
        },
        // Triggered when clicking the Finish button
        onFinishing: function(e, currentIndex) {
            var fv         = $('#profileForm').data('formValidation'),
                $container = $('#profileForm').find('section[data-step="' + currentIndex +'"]');

            // Validate the last step container
            fv.validateContainer($container);

            var isValidStep = fv.isValidContainer($container);
            if (isValidStep === false || isValidStep === null) {
                return false;
            }

            return true;
        },
        onFinished: function(e, currentIndex) {
            // Uncomment the following line to submit the form using the defaultSubmit() method
            // $('#profileForm').formValidation('defaultSubmit');

            // For testing purpose
            $('#welcomeModal').modal();
        }
    })
    .formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        // This option will not ignore invisible fields which belong to inactive panels
        excluded: ':disabled',
        fields: {
            username: {
                validators: {
                    notEmpty: {

                     // for asp.net i used element attribute to integerated with unobtrusive validation 
                     // message :$('username').attr('data-val-required')

                        message: 'The username is required'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: 'The username must be more than 6 and less than 30 characters long'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\.]+$/,
                        message: 'The username can only consist of alphabetical, number, dot and underscore'
                    }
                }
            },
            email: {
                validators: {
                    notEmpty: {
                        message: 'The email address is required'
                    },
                    emailAddress: {
                        message: 'The input is not a valid email address'
                    }
                }
            },
            password: {
                validators: {
                    notEmpty: {
                        message: 'The password is required'
                    },
                    different: {
                        field: 'username',
                        message: 'The password cannot be the same as username'
                    }
                }
            },
            confirmPassword: {
                validators: {
                    notEmpty: {
                        message: 'The confirm password is required'
                    },
                    identical: {
                        field: 'password',
                        message: 'The confirm password must be the same as original one'
                    }
                }
            }
          }
    });