HTML

<form id="formVa" method="post" style="margin-top:100px; margin-left:100px;">
    <label>
        Email
    <input name="user_email" value="" type="text" 
        data-validation-engine="validate[required,custom[email]]" 
        data-errormessage-value-missing="Required Field" 
        data-errormessage-custom-error="Invalid Mail" />
    </label>
    <label>
        Name
    <input name="user_name" value="" type="text" 
        data-validation-engine="validate[required]" 
        data-errormessage-value-missing="Required Field" />
    </label>
    <button type="submit">Submit</button>
</form>

JS

$('#formVa').validationEngine(
    'attach', {
        promptPosition : 'topRight:-90,15',
        scroll: false,
        autoHidePrompt: true,
        autoHideDelay: 2500,
        fadeDuration: 0.3,
        focusFirstField : false
    }
);

Code example

I use jquery validation engine for my forms and I want to show error messages in order. For example if email field is empty, show "Required Field" error message and if the user typed anything and email is incorrect, show "Invalid Mail" error message. But it show all messages together as below.

enter image description here

But I want it in order How can I do this?

有帮助吗?

解决方案

Theres a property you can set to show only one error per field

    maxErrorsPerField: 1

So you can do something like this

$('#formVa').validationEngine(
    'attach', {
        promptPosition : 'topRight:-90,15',
        scroll: false,
        autoHidePrompt: true,
        autoHideDelay: 2500,
        fadeDuration: 0.3,
        focusFirstField : false,
        maxErrorsPerField: 1
    }
);

FIDDLE

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top