Remove jquery validationEngine from form

I am using Position Absolute jQuery validationEngine , but I need to remove it after attaching to the form.

I have two submit buttons in my form - one for saving and one for saving as a draft.

I attach a validationEngine to the form when the "Save" button is clicked. If the verification fails, and the user clicks the Save As Draft button (passing the verification), the verification mechanism is still attached to the form from the moment you clicked save.

What I want to do:

  • allow the user to try to save
  • check completed and error displayed
  • and allow them to click the "Save as draft" button without any verification.

I tried the unbind function and it seems to work, but it completely breaks submit on the button. I just want to remove validationEngine and allow everything else to work as it was.

thank

+3
source share
3 answers

I added a function to the bottom of the javascript validationEngine file:

disable : function(formobj) {
    $(formobj).unbind("submit");
    $(formobj).die("submit");
    $(formobj).bind("submit", function() {
        return true;
    });
    $(formobj).live("submit", function() {
        return true;
    });
}

You are passing a jQuery form element. You could, of course, do this outside the javascript validationEngine file, it just made it easier for me to combine everything :-)

The important thing is that you use as unbind AND die.

+2
source

Create Validator Global Variable

var globalValidator = null

Follow validator logic ----

Then reset according to your logic with

function clearValidatorErrors(){
    if(globalValidator != null){
        globalValidator.resetForm(); 
    } 
}
+2
source

( , ).

, "submit".

$(this).bind("submit", function(caller){   // ON FORM SUBMIT, CONTROL AJAX FUNCTION IF SPECIFIED ON DOCUMENT READY
    $.validationEngine.onSubmitValid = true;
    $.validationEngine.settings = settings;
    if($.validationEngine.submitValidation(this,settings) == false){
        if($.validationEngine.submitForm(this,settings) == true) {return false;}
    }else{
        settings.failure && settings.failure(); 
        return false;
    }       
})

The problem is that if you have several submit event handlers attached to this form, it .unbind('submit')will kill all the events you linked to.

Assuming the event was the last connected, you can only remove the last event handler that will be dispatched:

 var events = $("#myForm").data('events');
 alert(events.submit.length); // should tell you how many events are bound..
 events.submit.splice(events.submit.length - 1, 1); // strip the last event
+1
source

Source: https://habr.com/ru/post/1733275/


All Articles