I am using jquery validation to validate a form. I am trying to accomodate a designer's whim and it is proving rather tricky. Basically the designer wants blue text "required*" for each mandatory input. If a mandatory input is not completed then the blue text should turn to red text i.e. only the color changes and the text remains the same.
I have put the blue text in a label with class "mandatory"
<label class="mandatory">required*</label>
I have also set all jquery validation required messages to the same "required*" text as in the label above. The plan is to hide the blue label and show the error label if it does not validate.
Here is where I feel I am doing something a bit stupid - In errorplacement and success I am running the following code:
errorPlacement: function (error, element) {
element.siblings(".mandatory").hide();
error.insertBefore(element.prev());
},
success: function (element) {
element.siblings("label.errorMessage").remove();
element.siblings(".mandatory").show();
}
However, this all works fine when the form is submitted - the blue label is successfully hidden and the error label is placed in the correct position.
If the user adds text to one of the error inputs then the "success function" above is executed properly and error label is hidden whilst the blue label is made visible.
If the user deletes the text from the same input that he just added text to, the input is validated individually and the error label is shown and this is where the issue is... the errorplacement code does not seem to execute again and now I have both blue and red labels visible.
Anyone know what I can do to hide the blue label at the point the input is validated again - BTW if the form is submitted again then all is fine?
Cheers
Wing
- I needed to insert before the
– wingyip Feb 28 '13 at 21:30