Dynamic field validation - works but cannot reference error bucket

Hi all,

I am trying to validate dynamically added fields.

I can use this for my rules:

'pageElements.*.value' => 'required',

…and I get this in my error bucket:

{"pageElements.0.value":["The pageElements.0.value field is required."]}

However when I try and output this to the user, using the below, nothing is shown:

@error('pageElements.{{ $key }}.value') <span class="error">{{ $message }}</span> @enderror

…but does if I reference the KEY specifically like:

@error('pageElements.0.value') <span class="error">{{ $message }}</span> @enderror

Of course, I need to reference each field with the $key value. But it looks like I cannot reference the error bucket with {{.$key }}.

Any ideas to get around this please?

OK, I found the correct way

@error('pageElements.'.$key.'.value') <span class="error">{{ $message }}</span> @enderror

…just needed to use PHP syntax instead of JS

pageElements.'.$key.'.value'