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
Hro
Hro3y ago
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?
trompix
trompixOP3y ago
@Harings Rob If I understood you correctly, then my answer is "yes"
ifox
ifox3y ago
@Harings Rob it's not a "json repeater" technically in this case, rather child blocks
Hro
Hro3y ago
Ok, I am checking
trompix
trompixOP3y ago
This is how this block looks in the blocks table
Hro
Hro3y ago
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.
Hro
Hro3y ago
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...
trompix
trompixOP3y ago
@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.
Hro
Hro3y ago
It's what you did with your custom rules. That's the current way to go for this.
trompix
trompixOP3y ago
@Harings Rob
Hro
Hro3y ago
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 method
trompix
trompixOP3y ago
Thanks 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!
Want results from more Discord servers?
Add your server