EMT
EMT

Reputation: 55

Remove JQuery validationEngine from the form

I have a form with 3 submit buttons. Only 1 will do the form validation other 2 must just submit the form without validation. I have the code but it works anyway for all 3 buttons and I only need 1 to be validating the form.

$(function() {
        $('#formID').validationEngine();
    });

Upvotes: 3

Views: 10148

Answers (3)

Zaman-A-Piri Pasa
Zaman-A-Piri Pasa

Reputation: 419

It works for me

        $("#buttonId1").click(function(){
            $('#formId').validationEngine('hideAll');
            $('#formId').validationEngine('detach');
            $('#formId').validationEngine('attach');
            if($("#formId").validationEngine('validate'))
                return true;
            else
                return false;                
        });

        $("#buttonId2").click(function(){
            $('#formId').validationEngine('hideAll');
            $('#formId').validationEngine('detach');
            return true;                
        });

        $("#buttonId3").click(function(){
            $('#formId').validationEngine('hideAll');
            $('#formId').validationEngine('detach');
            return true;                
        });

Upvotes: 8

Ian Stanway
Ian Stanway

Reputation: 610

Don't forget that the inline validation will still occur if you tab through the form fields, even though you would not want to do the validation when the user clicks one of the other submit buttons.

As an alternative to Jorge's suggestion, you could instantiate the validationengine on document ready as normal, and then detach the validationengine when one of the other buttons is clicked. You may also need to hide any prompts that are showing if you are submitting via Ajax and not leaving the screen.

$("#otherButtonId1").click(function(){
    // $('#formId').validationEngine('hideAll');
    $('#formId').validationEngine('detach');
 });

$('#otherButtonId2').click(function(){
    $('#formId').validationEngine('detach');
 });

~Cyrix

Upvotes: 2

Jorge Guberte
Jorge Guberte

Reputation: 11054

I don't know if this is exactly what you need:

    $("#buttonId").click(function(){
         $('#formId').validationEngine();
     });

    $('#otherButtonId').click(function(){
        $('#formId').submit();
     });

The first validates the form and the second simply submits it.

Upvotes: 2

Related Questions