2

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"/>
6
  • What do you mean when you say the submit 'is messing you all up'? Are you getting an error? What is working and not working? Commented Oct 30, 2013 at 15:39
  • When I click on Save, the whole page simply reloads without doing anything, it just shows the same form with the same values I had in the inputfields.
    – Rui Rocha
    Commented Oct 30, 2013 at 15:43
  • I don't believe you should be returning anything in your validate function. Try to take out the return true and add the return false to your onclick call in the button. Commented Oct 30, 2013 at 15:54
  • Thanks for the tip but it still does the same. I ends up reloading the entire page without doing anything, showing everything the same from the moment before I clicked Save.
    – Rui Rocha
    Commented Oct 30, 2013 at 16:05
  • Try : onclick="if (validateForm('SomeId',event) == false) return false;
    – brovasi
    Commented Oct 30, 2013 at 19:40

1 Answer 1

2

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);"/>
2
  • 1
    I concur with LaceySnr, I find it better not to mix two approaches, if I'm calling the logic from JS I just continue on and use actionFunction to call the post Apex side of things from JS too. Commented Oct 31, 2013 at 1:59
  • Sorry for only replying now, but this is a possible solution, it worked! Thank you.
    – Rui Rocha
    Commented Nov 4, 2013 at 16:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .