-1

I am using jQuery Validate plugin.

$("#loginForm").validate({
    highlight: function (element, errorClass) {
        $(element).parent('.form-group').addClass('error-sign-up');
    },
    unhighlight: function (element, errorClass) {
        $(element).parent('.form-group').removeClass('error-sign-up');
    },
    onfocusout:false,
    onkeyup:false,
    rules: {
        password: {
            required: true,
            minlength: 6,
        },
    },
    messages: {

        password: {
            required: "Please provide a password",
            minlength: "Your password must be at least 6 characters long"
        }
    }
})

After the submit I want to remover the error onkeyup on the element. Now the errors are removed only if the user click submit again.

I use

onfocusout:false
    onkeyup:false

for not execute the validation onfocusout/onkeyup

4
  • You can reset the form after submit like $("#loginForm").resetForm(); Nov 23, 2015 at 13:36
  • If you want the error class to be removed by the onkeyup trigger, then why are you disabling it? Remove onkeyup: false and then the error will be removed as intended.
    – Sparky
    Nov 23, 2015 at 15:05
  • You are causing the condition you're complaining about. If you don't want validation triggered on keyup or focusout, then clicking the submit a second time is the only trigger remaining.
    – Sparky
    Nov 23, 2015 at 15:12
  • @Sparky- you right. I confused Nov 23, 2015 at 15:14

1 Answer 1

0
onfocusout:false
onkeyup:false

You are causing the condition you're complaining about. If you disable the onkeyup and onfocusout triggers by setting them to false, then clicking the submit button is the only validation trigger that remains.

If you want the error class to be removed by the onkeyup or onfocusout trigger, then do not disable them. Remove onkeyup: false and onfocusout: false and then the errors will be removed as intended by the default settings.

6
  • @Sparky- you are right regarding the onkeyup, but not regarding the onfocusout. I can leave it true Nov 24, 2015 at 6:42
  • @SaritRotshild, I think you're confused... what do you mean "leave it true". You absolutely cannot set onfocusout to true as this will break the plugin. You need to read the docs: "A boolean true is not a valid value.". As per my answer, I said, "remove" the onfocusout option to use the default behavior, and never set it to true.
    – Sparky
    Nov 24, 2015 at 15:35
  • @Sparky- I read, and I can. I don't want that the validation will execute on focusout, only on submit Nov 25, 2015 at 12:49
  • @SaritRotshild, ok, but this is answering your original question!
    – Sparky
    Nov 25, 2015 at 18:18
  • @Sparky- As I said I just needed to remove the onkeyup Nov 29, 2015 at 9:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.