Get value from child block for validation in block class
Good afternoon! How to get the value of a field that is in Block -> Repeater -> Field?
It is necessary to check the field and display an error if the field, for example, is not filled.

12 Replies
Hey @User142 this is a block editor field with a json repeater? And you want to check/make sure that the repeater fields are filled in?
@Harings Rob If I understood you correctly, then my answer is "yes"


@Harings Rob it's not a "json repeater" technically in this case, rather child blocks
Ok, I am checking
This is how this block looks in the blocks table

The problem here is that basic validation rules only work agains simple data structures.
In the context of the block.
What you did here @User142 is fine https://discord.com/channels/811936425858695198/811986149064441927/1029969032058765403 but you can override getRules in your block class to make that owrk.
I added a pr for the future to improve on this, https://github.com/area17/twill/issues/1850 but do not expect this anytime soon.
GitHub
[3.x] Block validation: Add nested support · Issue #1850 · area17/t...
Currently when validating blocks, it is not possible to, for example, do: repeatername.*.title.en This is because the implementation only supports very basic fields. We can solve this by perhaps al...
@Harings Rob I don't quite understand how to implement this? Can you give an example if you don't mind? I already lost more than one day to solve this problem. Not much experience yet.
It's what you did with your custom rules. That's the current way to go for this.
@Harings Rob


I see, this is not easy to solve unfortunately. The issue is that the error key blocks[..][..] does not have the detail about the subfields..
the error key should be something like blocks[3][title][en]
I do not have an answer to this at the moment.
The only thing left what you could do is completely customize the
validate
method in your module repository.
but it's a private methodThanks a lot for trying to help. I look forward to a solution to this problem in future versions.
Already had the same idea, I'll see how I can implement it!