tdf#155121: XML Form Document: better take into account "not required"

Change-Id: Ibebdbc52f2bd7d09ec7aa5f072efef364249a291
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151733
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
diff --git a/forms/source/xforms/binding.cxx b/forms/source/xforms/binding.cxx
index 57d3727..b9f111a 100644
--- a/forms/source/xforms/binding.cxx
+++ b/forms/source/xforms/binding.cxx
@@ -207,7 +207,14 @@ bool Binding::isValid() const
{
    // TODO: determine whether node is suitable, not just whether it exists
    return maBindingExpression.getNode().is() &&
        isValid_DataType() &&
        (
            // tdf#155121, validity rules should be apply when field is required or
            // when the field is not required but not empty
            // so if the field is not required and empty, do not check validity
            (! maMIP.isRequired() && maBindingExpression.hasValue()
               && maBindingExpression.getString().isEmpty() ) ||
            isValid_DataType()
        ) &&
        maMIP.isConstraint() &&
        ( ! maMIP.isRequired() ||
             ( maBindingExpression.hasValue() &&