function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cmoylecmoyle 

Command Link with jquery validation.

So i'm trying to validate an apex form that submits via an ajax call. The form validation is being applied, however the form is still being submitted. It looks like the following:

 

 

<apex:form styleClass="createCaseForm" id="createCaseForm">
   <!--Form Elements-->

    <apex:commandLink rerender="status" action="{!submitCase}" styleClass="createCaseButton">
       <input type="image" value="Submit" src="..."/>
    </apex:commandLink>
</apex:form>

 Then the jquery that handles the validation looks like this:

 

 

$(document).ready(function(){
   $(".createCaseButton").click(function(event){
		if(mustCheck) {
			// Prevent submit if validation fails
			if( !checkForm($(".createCaseForm")) ) {
				event.preventDefault();
			};
		} else {
			mustCheck = !mustCheck;
		}
	});
});

 

Any idea how to prevent the form from being submitted when the validation fails?

 

 

Damien_Damien_

Why aren't you just doing your validation in Apex?

cmoylecmoyle

Because we're taking pages that a design company made for us and converting them to visualforce pages. The validation has a lot of styling elements involved with it, and it would be easiest for me to just find a solution to this issue than convert what they have done to apex.

MarkWaddleMarkWaddle

You might try adding calls to event.stopImmediatePropagation() and event.stopPropagation() after event.preventDefault(). If that doesn't work I would also try returning false as well.

 

If you can, I strongly recommend using validation rules or triggers to enforce validation like this. This way the validation will be enforced anytime the object is touched, whether from a standard form, VisualForce page, webservice call, etc.