문제

I'm having problems with jquery validation showing the default required validation message.

I add these textboxes dynamically using javascript. And I assume some class is missing for it to trigger the "data-val-required" attribute. Could that be the case?

Result after inspect:

<input class="required input-validation-error" data-val="true" 
    data-val-required="Custom error message here" type="text" 
    value="" id="Application_EducationReferences_0__Course"      
    name="Application.EducationReferences[0].Course">

<span class="field-validation-error" 
    data-valmsg-for="Application.EducationReferences[0].Course" 
    data-valmsg-replace="true">
    <span for="Application_EducationReferences_0__Course" class="">
      This field is required.</span>
</span>
도움이 되었습니까?

해결책

When you have client-side generated lists of input fields with unobtrusive validation you need to refresh, use this script to refresh the rules correctly:

$("form").data("unobtrusiveValidation", null);
$("form").data("validator", null);
$.validator.unobtrusive.parse($("form"));

this article describe that code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top