Context doesn't allow access to nested data
Open
Nobody has claimed this yet.
status:ready for adoption
type:bug
- Dominant language
- PHP
- Stars
- 167
- Forks
- 47
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 3
Description
What steps will reproduce the problem?
public function getRules(): array
{
return [
'submitForVerification' => [
new Required,
new BooleanValue,
],
'tasks' => [
new Each(
new Nested([
'push' => [
new Nested([
'isEnabled' => [
new Required(when: fn() => $this->submitForVerification),
new BooleanValue,
],
'content' => [
new Required(when: [???]),
],
])
],
])
)
],
];
}
What is the expected result?
I can set Required validator for content dependent on his sibling isEnabled value.
What do you get instead?
It cannot be done? Or it'll be ugly solution.
Additional info
| Q | A |
|---|---|
| Version | 2.1.x |
| PHP version | 8.2 |
| Telegram message | https://t.me/yii3en/10708 |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the PHP reproduction as the starting point and inspect how Nested, Each, and Required pass validation context. Determine how a Required condition can access the sibling isEnabled value inside each task's nested push data; done means the supplied rule can conditionally require content and the behavior is demonstrated with a regression case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100