-2

Using jquery.validate.js. Having a minor technical problem for my reset password form.

Validation working well. Got rules + messages before submitHandler.

Every messages goes directly to my

<span class="help-block" id="error"></span>

located below each input box. Thus I get live error messages below those boxes if I type anything wrong.

Problem: If I type everything correctly, no error messages will show up. And I get a success and new password. This is good.

But if I fail during typing, but afterwards correct it, and are successful making new password, I still get the "old" error in my above span help-block. Even if everything was a success.

So imagine I have this:

        $("#form-reset").validate(
        {
            rules:
            {   
                pass:  { required: true}
            },
            messages:
            {   pass: { required: dsaj jfaio daijo djaio}

            },
            /*AND HERE THE HELP-BLOCK TO GIVE CLIENT INFO*/
            {
            },
            /* here the submitHandler*/
            submitHandler: submitFormReset 
        }); 

        /* submitHandler kick off this function */ 
        function submitFormReset()
        {  
             /* At this point I would like to turn off validation*/
        }

I tried to remove the class and id on the help blocks in the above function. It will remove the info text, but since the input box become red (if fail) and green (if success) I still get a problem with a red color even with a success. So I guess I need to 'turn off' validation at this point instead. If that is possible...

Sparky
  • 98,165
  • 25
  • 199
  • 285
Hans Pede
  • 89
  • 1
  • 9
  • *"I know this is not much information, but i'm not sure how to explain it..."* ~ explain it by showing enough code to reproduce the issue. Where is your call to `.validate()` and the HTML markup for the `form`? – Sparky Jan 16 '17 at 17:10
  • @Sparky yeah I agree, but it a tons of code lol. If I somehow could turn off validate after `submitHandler` kick off (at this point there is no need for the input box validation anymore) it would actually fix my problem. The validation part is only for live info to the client... – Hans Pede Jan 16 '17 at 20:49
  • Nothing you've shown so far has much of anything to do with the problem you describe. When an error clears, the message goes away; unless you've done something to break it. Please **construct a working jsFiddle demo of the issue**. – Sparky Jan 16 '17 at 23:39
  • Again... show the code... what are you doing inside of `submitFormReset()`? Since the `submitHandler` only fires when the form is valid... you should never need to *"turn off"* validation at this point, or at any point. – Sparky Jan 16 '17 at 23:42
  • `/*AND HERE THE HELP-BLOCK TO GIVE CLIENT INFO*/` ~ <<< The most important code relevant to what you seem to be asking us... show this! – Sparky Jan 16 '17 at 23:46
  • Thanks for even answering my maybe bad question, but it would be almost a day job to post everything. I was just looking for someone who maybe had the same problem before.. – Hans Pede Jan 18 '17 at 00:34
  • Yet instead you posted almost nothing. You are not supposed to post "everything"; just post enough to reproduce the issue as explained in my previous comments. You asked why the message isn't clearing and nobody answered because when this plugin is used properly, the message always clears. – Sparky Jan 18 '17 at 00:52
  • if you are a good programmer you know what I was talking about already in my first post. Just because you can not answer my question does not mean that my question is totally retarded. But be my guest to give me as many minuses as you want to... – Hans Pede Jan 18 '17 at 02:40

1 Answers1

-1

I figured it out. I write answer here, maybe it can help others. After the submit handler I do things with the form.

For example I use

       $('#formZ')[0].reset();

If I remove this the form doesn't do strange stuff anymore after a success. I am not sure why this violates the jquery validator, but I guess I just have to skip the above reset.

Hans

Hans Pede
  • 89
  • 1
  • 9
  • If you had posted this code in your original question, somebody may have figured it out for you. – Sparky Jan 18 '17 at 00:52
  • Its a possibility. But this is 1 out of 250 lines in this block. I have to detect and inspect what code I should post here. 250 lines wont be read by anyone, and I understand why. In this case, maybe I shouldn't post my question, but anyway maybe it can help a future programmer – Hans Pede Jan 18 '17 at 02:37