Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm still struggling with the same problem about Parsley and semi validation. I have a form with 2 categories of fields

  • "Contact information" (17 fields)
  • "Company information" (5 fields)

The Contact information fields are mandatory. For The "Company information fields", the user must answer only if he has a company. So one radio button named "jform[company]" allows to answer to the question "Do you have a company".

  • If the answer is "No" - I want to apply a Semi validation (just Contact information fields)
  • If the answer is "Yes" - I want to apply a Full validation ( Contact information fields && Company information fields)

Here is my code: (It's highly inspired by the example on the official documentation: http://parsleyjs.org/doc/examples/events.html)

 $('#adminForm').parsley().subscribe('parsley:form:validate', function (formInstance) {
                if (formInstance.isValid('infos'))
                {
                    if ($("input[name='jform[company]']:checked").val() == 1) 
                    {
                        if (formInstance.isValid('comp') )
                        {
                            alert("Parsley - Full validation : OK");
                            return true;
                        }
                        else
                        {
                            alert("Parsley - Full validation : Fail");
                            formInstance.submitEvent.preventDefault();
                        }
                    }
                    else
                    {
                        alert("Parsley - Semi validation : OK");
                        return true;
                    }

                }
                else
                {
                    alert("Parsley - Semi validation : Fail");
                    formInstance.submitEvent.preventDefault();
                }
            });

My problem is that the submission of the form occurs only for the full validation. When I answer No to the question and I fill correctly contact information, the message "Parsley - Semi validation : OK" is displayed but the form is not submitted!

Do you have a possible explanation? Thanks very much

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
176 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's solved !

As explained by Milz in this post: Validate set of fields only if radio button is checked (conditional validation)

The problem was due to the misunderstanding of the use of "data-parsley-group".

Concerning Parsley.Remote.js, it's true that "formInstance.isValid" does not answer to the question about the validity of remote test. However the Behaviour is okay Because if the remote validation is false the form is Not Submitted and if it is right the form is Submitted!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...