[MGNLUI-3241] Composite Field: Add cross field validation between the subfields of the composite field Created: 04/Nov/14  Updated: 03/Mar/16  Resolved: 03/Mar/16

Status: Closed
Project: Magnolia UI
Component/s: forms
Affects Version/s: 5.2.10, 5.3.5
Fix Version/s: None

Type: New Feature Priority: Neutral
Reporter: Christian Ringele Assignee: Unassigned
Resolution: Obsolete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File AllEmptyOrNoneEmpty.java     Text File CrossFieldsComparator.java     JPEG File CrossFieldsValidatingCompositeField-Configuration.jpg     Text File CrossFieldsValidatingCompositeField.java     Text File CrossFieldsValidatingCompositeFieldDefinition.java     Text File CrossFieldsValidatingCompositeFieldFactory.java     XML File config.modules.training-templating.dialogs.myTextImage.form.tabs.tabMain.fields.pointOfInterest.xml     XML File config.modules.ui-framework.fieldTypes.crossValidatingCompositeField.xml    
Issue Links:
relation
is related to MGNLUI-3617 Cross/Conditional Field Validation fo... Closed
supersession
is superseded by MGNLUI-2542 Dynamic forms & cross-field interaction Accepted
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Date of First Response:

 Description   

Cross field validation is not a feature of the current Magnolia Form UI implementation.

I have created a general issue for requesting this feature as a general feature throughout form fields: MGNLUI-3240

In this ticket the the idea is to implement it for the CompositeField, as it would be a alternative to handle many of the use cases that occur of fields that need to be cross validated.
Possible use cases:

  • A "point of interest" CompositeField with the sub-fields "Longitude' and 'Latitude'. The field is not required, BUT if in one sub field a value is entered, the other also needs a value (no value or all have a value situation).

Idea:
Extending the CompositeField by a cross field validation of its sub fields.
Overriding the validate() method and delegating to a configurable field comparator class.

POC implementation:
I tried quickly such an implementation to test if it is possible.
I created:

  • CrossFieldsValidatingCompositeField.java which extends the CompositeField and its definition & factory class.
    The field delegates to an implementation of the CrossFieldsComparator.java interface to do the field comparison.
  • CrossFieldsComparator.java does the field comparison.
  • AllEmptyOrNoneEmpty.java is the implementation for this use case, checking if one field ha a value.

Attention: This is just a POC, not product ready code! It can be used in projects, but will probably need some adaptions.

Usage:

  • Add a 'fieldTypes' mapping of the FieldDefinition and the FieldFactory class. (added bootstrap file)
  • Use the CrossFieldsValidatingCompositeField class for a composite field.
  • Define the crossFieldsComparator property pointing to the implementation CrossFieldsComparator for the specific use case, in this case here the AllEmptyOrNoneEmpty.

Other use cases:
Just implement another version of CrossFieldsComparator.

Constraints:
I first tried to use a Vaadin Validator on the composite field.
This doesn't work because the Validator is decoupled form the invoked filed. So The Validator is not aware of any configured sub fields of a "Magnolia Composite Field".
Providing this values to the Validator to do a comparison would be very hackish (interlinking Magnolia Configurations and Vaadin Validators).



 Comments   
Comment by Mikaël Geljić [ 03/Mar/16 ]

While we acknowledge the importance of this feature, we intend to address it from this higher-level issue: MGNLUI-2542 (just rephrased it to "dynamic forms & cross-field validation", I also collected this requirement within composite fields there in description).
Therefore I'm closing this issue, feel free to watch MGNLUI-2542.

Generated at Mon Feb 12 09:04:38 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.