Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Unbind method for validationEngine #287

Closed
christian-kolb opened this Issue · 6 comments

3 participants

@christian-kolb

I use the validationEngine to validate a from element in a web application. The data of the form is send via AJAX and the form is never submitted. The form is also used several times and has be be resetted.

When I reset the required fields I get error messages from the validationEngine because they aren't filled any more. That's a perfectly right behaviour, but very annoying when resetting a form on purpose.

I would like to unbind the validationEngine from the form, then reset it and add the validationEngine again, but I didn't find any kind of unbind method in the validationEngine.

Could you add such an unbind method?

@orefalo
Collaborator

Hi,

did you try the detach() method ?

@christian-kolb

Hi,

do you mean with the following?

.validationEngine('detach');

Yes I tried it, but it didn't had any effekt at all.

@orefalo
Collaborator

Looking at the code, detach should do the trick. it unregisters the events.

Could you please copy paste, the exact code that you are using.

@christian-kolb

When I show the form I call

$("#formid").validationEngine();

On save I call

$("#formid").validationEngine('validate')

Then I reset the form with the following code:

resetForm($("#formid"));

function resetForm(form) {
    form.validationEngine('detach');
    resetFormFields(form);
    form.slideUp(500);
}

// Reset all form fields
function resetFormFields(form) {
    $(':input', $(form)).each(function(i, item) {
        switch(item.tagName.toLowerCase()) {
            case 'input':
                switch(item.type.toLowerCase()) {
                    case 'hidden':
                    case 'text':
                        item.value = '';
                        break;
                    case 'radio':
                    case 'checkbox':
                        item.checked = '';
                        break;
                }
                break;
            case 'select':
                item.selectedIndex = 0;
                break;
            case 'textarea':
                item.value = '';
                break;
        }
    });
}

And in the moment I reset the form, I get the error messages on top of each reseted field.

@christian-kolb

I maybe found something.

Right before I reset the form, I check if the form ist valid with the following call:

$("#formid").validationEngine('validate');

When I delete this line, the detach works perfect and I can reset the form without any error messages.

But I need to validate the form before sending the data to the server. Have I done anything wrong there or is this a bug?

@posabsolute
Owner

Hi christian,

the engine wqill automatically validate the form when submitting it, 'validate' is used if you want to directly validate the form without submitting it, as for detach, I just tested it, and it seems something is wrong in your code,

In any case withotu a live example it is hard to debug

@posabsolute posabsolute closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.