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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…