Ideas on why JS causes rails validations to be ignored - javascript

I have a rails application that uses $('form').submit(), however if it fails the validation once and then it is clicked again it completely ignores the validations and generates a routing error. Now, If I use the regular button it does not do this unless the JQuery submit exists with it. Why do you think that is?
Update: JQuery finds the form values looking for anything within the <form> tags.

Okay the problem was not related to the JavaScript at all. What was happening is a variable was getting a value of nil causing a routing error for the path. Adding a check for nil and reassigning it if it is fixed it.

Related

Generic exception submitting form via JavaScript

I am moving an application from JBoss 7.1.q to WildFly. Parts of the navigation are done with by creating a form in JavaScript and submitting it via the submit method. All of these calls still work with the exception of one.
Instead of navigating to the page, I get a message of
A Generic Exception Occurred while accessing this page.
I grepped through the code to see if someone had created a window.onerror function to catch exceptions but could not find one. Even more odd, I added one to the js page and it failed to catch the exception.
I have waded through the JavaScript with Firebug and Chrome dev tools and from what I can see, everything looks to be OK, but clearly it is not.
I know it is not much to go on. I am looking for ideas for the next steps to triage this issue. I also find it curious that this problem did not appear until the move to WildFly but I have no clue how that could cause this issue - maybe the form posting is more strict?
Any ideas?

flowplayer html validation

Ok, Im trying to rebuild a clients website thats long over due for cleanup on the backend and under the hood. This client uses flowplayer for most of the videos seen on any of there sites, and while attempting to validate my code via w3c validator I notice that the validator is throwing 2 errors both pertaining to flowplayer in this case.
http://validator.w3.org/check?uri=http%3A%2F%2Fv2.newyorkbarshow.com%2Fhome&charset=%28detect+automatically%29&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.3
I am using the latest flowplayer out, and following there example (which I don't know if that validates either). So I am wondering if it doesn't validate out of the box, if anyone happens to know a means of correcting it so it will validate.
You need to add data attribute with value "/static/imgs/static/VidAd4BarShow.swf" in your object tag.
note : I see this happens before flow player executes anything within your source...

MVC3 Form Validation causing an error in Qunit tests

I have been working with a MVC3 application that is using jquery form validation and in my script that interacts with the remote validation process to see if a record name is available I am using the
$('#Name').rules().remote.complete = function (xhr) {
check to change form variables etc. When I reference that script from my QUnit tests I get the following error.
Uncaught TypeError: Cannot read property 'form' of undefined
I can fix it by putting the following conditional above the .rules() check but is there a better way to do this?
if (document.forms.length > 0) {
I suppose I could fire up the page in IIS and do JS unit tests that way but that seems less isolated. I would not want to have this .rules() check in some other JS file because combining the JS files is a way to improve speed. Anyone ran across this and found a better way to do it? Thanks in advance.

MVCControlsToolkit and Validation

Today I installed the MVC3ControlsToolkit from NuGet, and proceeded to add a a DateTimeFor control to a Scaffolding generated page. I only changed one line of code, but the page was no longer visible, and an exception was thrown, saying validation was happening twice.
If I set UnobtrusiveJavaScriptEnabled to false in my Web.config, I can view the page. Funny thing is that if I restore the page to it's previous state (ie. default config) the error persists.
The error I get is: "Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required"
If anyone can shed some light on this, I'd really appreciate it.

jQuery plugin: Validation can't be customized without setting all fields to 'required'?

I've spent the day looking at jQuery plugin: Validation by Jörn Zaefferer. I notice that it works fine as long as you call the validate() method without options. In my little squalid world, as soon as I add options, like errorPlacement, I notice that validation ignores form fields that are not marked required. I also notice that many, many demos mark all fields required---or do not pass options. Am I writing about anything familiar here? Or should I astral project to a parallel universe?
Note: This is to close the question out and provide info to resolve this to the next person finding the question since the OP has resolve the issue.
If there are any errors in the options, it will act the same as ignoring the fields, this isn't the validation plugin behavior per se, but rather how javascript works overall...any errors and it blows up (in mosts cases).
Double check all your options and use either Chrome's tools or FireBug to see if there are any script errors at all. Judging from your question, this seems the most likely culprit, fixing any errors in your options/errorPlacement will eliminate the onstacle in making the validation plugin work.
Also for testing, it's very helpful to use the debug option on the validation plugin, like this:
$("form").validate({
//other options
debug: true
});
This prevents the form from actually submitting, allowing you to tweak the validation much faster.

Categories