English 中文(简体)
Jquery 审定——在急切验证期间显示验证摘要?
原标题:Jquery validation - show validation summary during eager validation?

是否可以通过 j格鉴定,用急切的鉴定来显示验证摘要?

I m using MVC 3 (if it matters) and my forms validate when each element loses focus:

$( #myform ).validate({ onfocusout: function(element) { $(element).valid(); } };

This shows individual errors on each field, however I also want to show those errors in the validation summary block. However, that validation summary only shows up when the form is submitted, not on lost focus.

I ve tried hooking into showErrors, however that only gives me the current field error, not the current list of errors.


For completeness, here s the form code:

@using (Ajax.BeginForm(...))
{

  <div class="field-panel">
    @Html.EditorFor(m => m.PatientID)
    ...

  </div>
  <input type="submit" class="carecon-button-next" value="Next" />
  @Html.ValidationSummary(null, new { @class = "validation-summary" })
}
最佳回答

奥基,我认为我是这样说的。

问题实际上是因为使用了与MVC 3号案的不侵犯性认证,因为它对你来说是首选。 因此,汇兑验证的唯一途径是使用<代码>form.data(“打字器”)制定。 但是,试图制定<代码>errorLabelContainer。 通过这种方法,即:

$("#form").data("validator").settings.errorLabelContainer = "#messageBox";

......不工作,因为j Query的验证只使用其内在功能中的这一价值,没收诸如集装箱等其他环境的nch。 我在设定了<代码>errorLabelContainer后,再次尝试介绍其所做的工作,甚至打上了$(“#form”).data(“validator”)。

So I took a different approach. First, I provided a place for MVC to put in the individual error strings using @Html.ValidationMessageFor(), and adding display:none to keep it hidden:

@using (Ajax.BeginForm(...))
{

  <div class="field-panel">
    @Html.EditorFor(m => m.PatientID)
    @Html.ValidationMessageFor(m => m.PatientID, null, new { style = "display:none"})
    ...

  </div>
  <input type="submit" class="carecon-button-next" value="Next" />
  <ul id="error-summary">
  </ul>
}

然后,在<代码>showErrors上 电话:后,请打电话defaultShowErrors():

    $("#form").data("validator").settings.onfocusout = function (element) { $(element).valid(); };
    $("#form").data("validator").settings.showErrors = function (errorMap, errorList) {
        this.defaultShowErrors();
        $("#error-summary").empty();
        $(".field-validation-error span", $("#form"))
            .clone()
            .appendTo("#error-summary")
            .wrap("<li>");

    };

这使我看到了我所想的行为,显示/将验证错误作为摘要中的一个清单,因为用户填写了表格中的领域。

问题回答

我遇到了类似的麻烦,并写了这封信,似乎很容易找到你所寻求的行为:

function EnableEagerValidation(){
    var itemsNeedingValidation = $( *[data-val="true"] );
    itemsNeedingValidation.each(function () {
        $(this).blur(function(){$(this).closest("form").valid();});
    });
}

http://jquery.bassistance.de/validate/demo/marketo/"rel=“nofollow”>demo page ;invalidHandler;以及编制错误摘要的代码。 但是,它是在<代码>form上启动的,提交的不是你要求的。

invalidHandler: function(e, validator) {
    var errors = validator.numberOfInvalids();
        if (errors) {
            var message = errors == 1
                 ?  You missed 1 field. It has been highlighted below 
                 :  You missed   + errors +   fields.  They have been highlighted below ;
                 $("div.error span").html(message);
                 $("div.error").show();
        } else {
            $("div.error").hide();
        }
},

然而,errorLabelContainer: http://docs.jquery.com/Plugins/Validation/validate”rel=“nofollow” 根据号文件,所有错误标签均在一份无顺序的名单中标明,该编号为“messageBox”,由选择人指定为错误保管人。 所有错误内容均载于电文内,以编制一份电文清单。

errorLabelContainer: "#messageBox",

此处采用<代码>onfocusout显示验证的粗体。 没有任何纽子来证明这一点。 <代码>#messageBox收集的所有信息。

http://jsfiddle.net/sstarty672/bAN2Q/





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...