jQuery validate(); Only validate on click of one type of submit button
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;
$(docu开发者_运维知识库ment).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
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" />
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.
精彩评论