This is a migrated thread and some comments may be shown as answers.

Unobtrusive Validation Fires Multiple Times

1 Answer 448 Views
Window
This is a migrated thread and some comments may be shown as answers.
Reafidy
Top achievements
Rank 1
Iron
Reafidy asked on 24 Jun 2018, 08:07 AM

I am trying to use unobtrusive validation for an ajax form inside a window.  However if the window is opened multiple times then closed the validation fires multiple times.   If I move the script to the main page then the validation does not fire at all.

Where should I place the validation script and how do I get it to fire only once?

 

@model MyProject.Models.Input
 
@{
    Layout = null;
}
 
 
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.js"></script>
<script src="~/lib/jquery.unobtrusive-ajax/dist/jquery.unobtrusive-ajax.js"></script>
@*<form asp-controller="Home" asp-action="Edit"
    data-ajax-begin="onBegin" data-ajax-complete="onComplete"
    data-ajax-failure="onFailed" data-ajax-success="onSuccess"
    data-ajax="true" data-ajax-method="POST">*@
 
<form asp-controller="Input" asp-action="Edit"
      data-ajax-complete="onComplete"
      data-ajax-failure="onFailed" data-ajax-success="onSuccess"
      data-ajax="true" data-ajax-method="POST">
 
    <input type="hidden" asp-for="InputID" />
    <input type="hidden" asp-for="TemplateID" />
    <label asp-for="Input" class=""></label>
    <input asp-for="Input" autocomplete="off" class="k-textbox" />
    <br />
    <label asp-for="Description" class=""></label>
    <input asp-for="Description" autocomplete="off" data-val="true" class="k-textbox" />
    <span asp-validation-for="Description" class="text-danger"></span>
    <br />
    <label asp-for="DisplayOrder" class=""></label>
    <kendo-numerictextbox for="DisplayOrder" format="0" />
    <br />
    <label asp-for="Format" class=""></label>
    <input asp-for="Format" autocomplete="off" class="k-textbox" />
    <br />
 
    <input type="submit" value="Save" class="btn btn-primary" />
 
</form>

1 Answer, 1 is accepted

Sort by
0
Accepted
Bozhidar
Telerik team
answered on 28 Jun 2018, 05:50 AM
Hello,

This is due to the dynamic loading of content inside the Window. In general this is a jQuery issue, concerning any dynamic content, being window or a partial view. I can refer you to the following discussions, where solutions are discussed:
https://stackoverflow.com/questions/9321040/unobtrusive-validation-not-working-on-dynamically-added-partial-view
https://stackoverflow.com/questions/4406291/jquery-validate-unobtrusive-not-working-with-dynamic-injected-elements/5783020#5783020

Regards,
Bozhidar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Window
Asked by
Reafidy
Top achievements
Rank 1
Iron
Answers by
Bozhidar
Telerik team
Share this question
or