13

I have a quite perflexing problem that I have researched and come up blank;

Scenario: I have a form, with the jQuery bassistance.de's validate() plugin (http://docs.jquery.com/Plugins/Validation).

Does the job on submit perfectly, however; I two types of submit button.

One submits the form as usual, triggering my back-end validation and return errors or success.

The other type, is to all intense and purposes a submit button to the browser, however it tells my back-end to add another section of inputs (ie, a repeating element for employment history.) I want the user to be able to add the repeating elements without having to complete the rest of the form first. So clicking the second type of submit I want to BYPASS the validate();

HTML:

<form method="post" action="" id="ApplicationForm" name="ApplicationForm">

  <input id="job1" name="job1" class="required"/>
  <input type="submit" name="delete_job1" value="Delete" class="delete" />

  <input id="job2" name="job2" class="required"/>
  <input type="submit" name="delete_job2" value="Delete" class="delete" />

  <input type="submit" name="add_job" value="Add Job" class="add" />

  <input type="submit" name="ApplicationForm" value="Save Details" class="submit" />

</form>

I have tried a listener for the true submit button below, but this just stops the validate all togerther;

$(document).ready(function()
{
    var submitPress

    $(".submit").click(function()
    {
        submitPress = true;
    });

    if (submitPress)
    {
        $('form#ApplicationForm').validate();
    }
});

I guess this is because the validate(); listeners is setup on the initial loading of the page, not upon submit...

Is there there a rule or setting for validate(); I am missing, that I could utilise, or even a good hack with good old fasioned JS.

Muchos gratias who ever can help, i'm at my whits end.

Yours Sincerely, Working Late, AGAIN , Developer

2 Answers 2

23

http://docs.jquery.com/Plugins/Validation/Reference#Skipping_validation_on_submit

basically, add class="cancel" to the submit buttons which you don't want to trigger validation.

<input type="submit" value="I Validate" />
<input type="submit" class="cancel" value="I skip Validation" />
Sign up to request clarification or add additional context in comments.

3 Comments

Cheers Chris, thats the Badger... Don't know how I missed that. Think I entered the twilight zone last night and had to go home.
sweeeet... using jquery mobile, thought it might be a data-* attribute. thanks @rambo coder
As of 2015 the class="cancel" is now deprecated. You now add the 'formnovalidate' attribute. Click on the link to see latest documentation.
0

its not working,because the id you have provided of your input element,that become change like this submit_1_btnSubmit ,after page load

so to get rid this error you may use ClientIDMode="Static"

(if you are working on asp.net)
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" CssClass="Submit" ClientIDMode="Static" />

else

you may access `clientIDmode`  property on button control dynamically.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.