Show validation messages on detached repeat field

Hey guys,

we are currently on A12 version 2023.06-ext4.

And we are using a detached repeat in one of our form models.

Specific fields inside the repeat are validated using validation rules and are required in certain circumstances.

The problem is that the validation messages only show up after pressing the “Save” button outside the detached repeat screen. We would like them to be there already when pressing the “Commit/Apply” button inside the detached repeat screen.

The one thing we tried is to listen to “leaveDetachedRepeatRow” events and dispatching the “validateFull” command. After that querying the validation messages using “UiStateSelectors.messages”, but that does not seem to work as we don’t have any messages there, maybe due to a race-condition.

api.dispatch(
    FormEngineActions.command({
        activityId: latestActivity.id,
        engineEvent: Commands.validateFull()
    })
);

const selectEngineState = FormEngineSelectors.engineState(activityId);
const engineState = selectEngineState(state);

const selectErrorMessages = UiStateSelectors.messages();
const errorMessages = engineState && selectErrorMessages(engineState);

// errorMessages are just empty

Does someone know if and how this is possible?

Or maybe we are getting something wrong with our approach and someone knows how to fix the code?

Hey @raffael-broad-linden,

this should already be the default behavior: If the detached repeat screen is left, a partial validation is triggered.
If any of the fields that are needed to do the validation, has no control on the DetailScreen, you should mark it as Global in the Document Model (see documentation regarding relevant fields)

The Global flag will work again correctly in 2024.06. For the 2023.06 release line, you need a workaround: place a control of the needed fields onto the DetailScreen and make it invisible.

Just to add a bit more information on partial validations. The documentation that @felix-blazing-river linked to describes how the fields that are on the detached repeat screen will be validated. In addition, I wanted to highlight that:

  1. Controls hidden by a dependency will not be considered by a partial validation.
    This means that you if you want to have “invisible” fields on a Detached repeat screen, you need to add them, ensure that they are read-only and then user helper classes so that the font and background colors match.
  2. Rules that reference a FieldList using the Asterisk Operator will not be triggered by a partial validation.
    This means that you cannot model rules that compare your fields on the Detached repeat screen to the rest of the fields in the FieldList. For example, AtLeastOneFieldFilled(../MyRuleGroup*/MyField Having [MyField] == "TestValue"). If you want to achieve this, you need to compute the validation result (true or false) onto the Detached repeat screen using a helper Field which you then hide as described above.
    This makes sense on a Detached repeat screen as you cannot see the other fields but is also true for Embedded and Inline Repeats, where the other fields are visible on the screen.

I’ve created two simple example models to show this.

I’ve got a field outside the repeat and a field in the repeat. I want the rule to fire if they are both filled. These model shows the helper fields that I’ve modeled and how I’ve used the Helper Classes to have “invisible” fields.

2023.06-ext4 models
DetachedRepeatExample_DM.json (9.0 KB)
DetachedRepeatExample_FM.json (7.3 KB)

Hi @raffael-broad-linden
as already described above, it is to be expected that the rule does not fire if it relies on fields, that are not available on the detached repeat detail screen.
If this is not the case in your model, can you please attach some models to reproduce the behavior, so that I can investigate further?

Hi guys, thank you for the numerous feedback!

The issue was indeed caused by a field which was used in the validation, but had no Control inside the form model. Adding a Control for it solved it for me, thank you, @felix-blazing-river, for the tip!

And also thank you, @malcolm-silver-ice and @tobias-amber-cliff, for the additional information and examples!

Wish you a nice day and happy Easter.