Search code examples
jqueryjquery-validateunobtrusive-validation

Jquery Validation ShowErrors method shows error in a Label instead of Span


My question is somewhat related to this

Here is a JsFiddle Link to see what is happening I am using jquery validation version 1.14.0.

<Form id="myform">
        <div class="editor-label">
          <label for="FirstName">First name</label>
        </div>
        <div class="editor-field">
          <input class="text-box single-line" id="FirstName" name="FirstName" type="text" value="">
          <span class="field-validation-valid" data-valmsg-for="FirstName" data-valmsg-replace="true"></span>
 </Form>

 var form= $("#myForm");
  var validator=$("#myform").validate();
  validator.showErrors({
        "FirstName": "test error"
    });

Also validator.valid() returns true if I use validator.showErrors to make the input invalid.How can I make validator.showErrors make the form invalid in addition to showing the errors?


Solution

  • You can write your own logic to show errors in <span> instated of label

    Please see here for full example. Fiddle