Visualforce onclick doesn’t execute action or rerender

I’m having a problem. Up till’ now, I was using my own jQuery build to do this. Meanwhile, I was told to change it to jQuery validation plugin. It was working before but now I’ve been stuck in trying to make the action of the command execute and rerender (it doesn’t even rerender at the moment). The field validation work fine, just the submit is messing me all up. I’d appreciate any help or advice you could give.

        function validateForm(id,e){

        var form =  jQuery('[id$='+id+']');

        form.validate();             

        jQuery('[id$=name]').rules("add",{
            required: true,
            minlength: 5
        });
        jQuery('[class$=costPercentage]').rules("add",{
            required: true,
            number: true
        });

        jQuery.validator.messages.required = "You better have entered a value.. or else!";
        jQuery.validator.messages.equalTo = "No silly, you're supposed to type the same set of characters AGAIN.";
        if(!form.valid()){
             e.preventDefault();
             return false;

        }    
        return true;
    }

<apex:commandButton value="Save" onclick="return validateForm('SomeId',event);" action="{!createFunction}" rerender="SomeForm"/>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

How about using an <apex:actionFunction> instead of using the action parameter?

<apex:actionFunction name="doCreate" action="{!createFunction}" rerender="SomeForm"/>

snip

  // on passing validation
  doCreate();
}

snip

<apex:commandButton value="Save" onclick="return validateForm('SomeId',event);"/>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x