last day (14 days later) » 

11:42 AM
0
A: validations error messages not showing on the view

User3250Add these lines in your view: <script> $(document).ready(function(){ var form = $('form')//Give Id prop to your from .removeData("validator") .removeData("unobtrusiveValidation"); $.validator.unobtrusive.parse(form); }); <script> Also make sure you add jquery.validate.js and jquery.validate.u...

 
Tom
Hi tried the following @using (Ajax.BeginForm("ActivityWorkLog_Create", "Activity", new AjaxOptions { HttpMethod = "POST", OnSuccess = "OnSuccess", OnFailure = "OnFailure" },new { id = "ActivityWorkLogForm" })) {
function OnSuccess(response) { $("#statusMessage").text("Status updated"); alert("Success"); var form = $("#ActivityWorkLogForm") .removeData("validator") .removeData("unobtrusiveValidation"); $.validator.unobtrusive.parse(form); }
I cant see my alert in the success getting called. Are you sure the success gets called when the model.state returns false
 
No, I mean how you load your VIEW not your submit function in the view. You use controller action to return View?
 
Tom
Yes I use the controller action to return to the view
 
Updated my answer. Please read this for how jQuery Unobtrusive Validation works.
 
Tom
I have updated the post with the bundle.config. I can see the jss files have been loaded on form load but I am getting the error Microsoft JScript runtime error: Unable to get value of the property 'unobtrusive': object is null or undefined
I remove those two and added this "~/Scripts/jquery.unobtrusive-ajax.min.js" and error is gone
So currently the failure measure triggers when required fields are not added
Do I need to put that code in the failure message
 
11:42 AM
Ok, so your validation messages are showing up right?
 
Tom
Sorry my bad. I checked the developer tools . I am still getting the error message
No it is not showing
All i can see is my failure message firing. function OnWorklogStatusFailure(response) { alert("Failure"); }
 
Ok, it seems bit difficult issue to figure out.
Your Required field validations are not working?
 
Tom
yeah true. Need to nail this down
No they arent
My other forms that dont use ajax works fine
do you think its work not doing ajax submit
 
Yeah, I think you should use jquery ajax post instead
 
Tom
right
 
11:48 AM
You know how to do it right?
 
Tom
some post mentions the ajax files that you suggested while one said that that hasnt got to do with ajax
i dotn know how to solve the error message Microsoft JScript runtime error: Unable to get value of the property 'unobtrusive': object is null or undefined
 
ahh your unobtrusive file isn't loaded still
 
Tom
I can see those files in the view source
 
Ok
 
Tom
the question is which are the right files. One post says this file "~/Scripts/jquery.unobtrusive-ajax.min.js"
 
11:51 AM
do one thing just drag drop from your folder
both ajax obtru and non ajax
into your view
don't use bundle
 
Tom
can you explcitly tell me which files
 
jquery.unobtrusive-ajax.min.js
jquery.validate.unobtrusive.js
jquery.validate.js
 
Tom
let me give it a quick try.
 
ok
 
Tom
isnt this
jquery.validate.js first in the order
 
11:56 AM
yes
 
Tom
12:06 PM
seems like working. Need to test it properly. But I still feel having local reference of these scripts isnt a good idea
 
Yes, I think you are loading that bundle files more than once
Hence the issue
 
Tom
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.min.css",
"~/Content/Site.css"
));

bundles.Add(new StyleBundle("~/Content/kendo/css").Include(
"~/Content/kendo/2017.1.223/kendo.common.min.css",
"~/Content/kendo/2017.1.223/kendo.mobile.all.min.css",
"~/Content/kendo/2017.1.223/kendo.dataviz.min.css",
"~/Content/kendo/2017.1.223/kendo.default.min.css",
"~/Content/kendo/2017.1.223/kendo.dataviz.default.min.css"
));


bundles.Add(new StyleBundle("~/Content/custom/css").Include(
 
in bundle vaidate should be before unobt right?
Ok, i ll push off now
happy coding!
 

last day (14 days later) »