# HG changeset patch # User Paul Boddie # Date 1354495629 -3600 # Node ID 0065b36bc983b65ec5782c7283f51146121367b2 # Parent c25dbe02e053f0201ca37daefe40340ffb08662e Fixed short-circuiting of form section validation for already invalid forms. Added form message regions to the validation structure. Suppressed error messages for new form sections. diff -r c25dbe02e053 -r 0065b36bc983 MoinForms.py --- a/MoinForms.py Mon Dec 03 01:15:19 2012 +0100 +++ b/MoinForms.py Mon Dec 03 01:47:09 2012 +0100 @@ -92,7 +92,7 @@ if isinstance(definition, dict): if value: for element in getSectionElements(value): - valid = valid and self.validateFieldsUsingStructure(element, structure[key]) + valid = self.validateFieldsUsingStructure(element, structure[key]) and valid # Validate individual fields. @@ -104,7 +104,14 @@ if not value or not value[0]: if field_args.get("required"): - errors.append(_("This field must be filled out.")) + + # Detect new parts of the structure and avoid producing + # premature error messages. + + if not fields.has_key("_new"): + errors.append(_("This field must be filled out.")) + else: + valid = False else: # Test for unacceptable values. @@ -214,10 +221,13 @@ # Where a section is found, get details from within the section. - elif format == "form" and attributes.has_key("section"): - section_name = attributes["section"] - section = structure[section_name] = {} - getFormStructure(body, request, path and ("%s/%s" % (path, section_name)) or section_name, section) + elif format == "form": + if attributes.has_key("section"): + section_name = attributes["section"] + section = structure[section_name] = {} + getFormStructure(body, request, path and ("%s/%s" % (path, section_name)) or section_name, section) + elif attributes.has_key("message"): + getFormStructure(body, request, path, structure) # Get field details from other kinds of region.