0

I am a beginner in jQuery manipulation. I have a form that is validated in server side with no errors(problems), but when I try to add a second form validation it doesn't work, the while validation don't work anymore nothing is displayed.

Here is my code :

    <script>
function seen() {
    $("#mss").slideUp(1000);
};

    $(document).ready(function() {
        setTimeout(function() {seen();}, 5000);

        $("#ForgotPass").validate({
            rules : {
                'ForgotPass:mailprofile' : {
                    email : true,
                    required : true
                }
            },
            messages : {
                'ForgotPass:mailprofile' : {
                    email : "Veuillez entrer une adresse e-mail valide",
                    required : "L'adresse e-mail est vide"
                }
            }

        });

    });
</script>

The second validation I need to add :

$("#loginFormId").validate({

                rules : {
                    'loginFormId:mailprofile' : {
                        email : true,
                        required : true
                    }
                    'loginFormId:password' : {
                        required : true
                    }
                },
                messages : {
                    'loginFormId:mailprofile' : {
                        email : "Veuillez entrer une adresse e-mail valide",
                        required : "L'adresse e-mail est vide"
                    }
                    'loginFormId:password' {
                        required : "Le mot de passe est vide"
                    }
                }

            });

JSF Form loginFormId :

<h:form id="loginFormId" prependId="false">
<h:inputText class="form-control" id="mailprofile" value="#{userloginMB.mailprofile}"></h:inputText>
<h:outputLabel id="outLblUserMailId" for="mailprofile"
name="outLblUserMailNm" value="E-mail"></h:outputLabel>
</h:form>

Form ForgotPass

<h:form id="ForgotPass" class="form floating-label">
<h:inputText class="form-control" id="mailprofile" value="#{userloginMB.mailprofile}"></h:inputText>
<h:outputLabel id="MailidL" value="E-mail" for="mailprofile" name="MailnmL"></h:outputLabel>

The question : How to do both validation or even more while each have a different id ?

Chaibi Alaa
  • 1,346
  • 4
  • 25
  • 54
  • 1
    Remember: when having trouble in jQuery, focus on client side (HTML) source code, not on server side (JSF) source code. As told several times before: http://stackoverflow.com/q/7927716. So, whenever JavaScript/jQuery users here ask for the source/snippet/fiddle, do not show the JSF source code, but its generated HTML output instead (of course, preferably in MCVE flavor). In case you get the answer then it's just a matter of rewriting server side (JSF) code in such way that it generates exactly the desired HTML/JS/jQuery output. – BalusC Oct 02 '15 at 07:30
  • The code i posted is not generated bu jsf but is on the xhtml page and it doesnt change from development side to browser side. Should I post jsf forms ? Okey I just forgot aboit the reproduction of this. – Chaibi Alaa Oct 02 '15 at 11:42
  • *"not generated bu jsf "*, *"doesnt change from development side to browser side"* Exactly. So, not a JSF/XHTML problem. You don't need to mention/tag them. That's only confusing to JS/jQuery users. – BalusC Oct 02 '15 at 11:43

2 Answers2

1

You can try :

$('form').each(function(){ ... generic validation for all forms here ... });

And put the validate(s) into the each

1

You are missing the {} even if the function receives only one param like required : true, it should be surrounded with { }, I know, messy and unusefull, but worked for me.