yiisoft / yiisoft/validator

Context doesn't allow access to nested data

Open
#752 0 comments 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.