Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add validation to the depend-on field #6326

Closed
bocanhcam opened this issue Apr 2, 2024 · 5 comments
Closed

Cannot add validation to the depend-on field #6326

bocanhcam opened this issue Apr 2, 2024 · 5 comments
Labels
needs more info More information is required

Comments

@bocanhcam
Copy link

I have this simple code that requires users to fill in the billing_name if is_billing is true.
However, the validation is not working at all. I still can submit the form without filling in the billing_name when is_billing is checked.
show() still works.

public function fields(NovaRequest $request)
    {
        return [
            Boolean::make('他に請求先を指定','is_billing')->onlyOnForms(),
            Text::make('請求先氏名','billing_name')
                ->hide()
                ->dependsOn(['is_billing'], function (Text $field, NovaRequest $request, FormData $formData) {
                    if ($formData->is_billing === true) {
                        $field->show()->rules(['required', 'max:50']);
                    }
                })
                ->placeholder('(半角50文字まで)')
                ->onlyOnForms(),
        ];
    }
  • Laravel Version: 10.48.4
  • Nova Version: 4.33.1
  • PHP Version: 8.2.17
@webard
Copy link

webard commented Apr 2, 2024

Same in my app, rules set on field in dependsOn closure are not respected.

@crynobone crynobone added the needs more info More information is required label Apr 2, 2024
@crynobone
Copy link
Member

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@webard
Copy link

webard commented Apr 2, 2024

Here is reproduction repo: https://github.com/webard/nova-issue-6326 , in User resource is sample.

Bug occurs when other fields is depend on Boolean field (Select works correctly, I didn't check all fields).

@crynobone
Copy link
Member

Does $formData->bool('is_billing') === true worked for your use case?

@bocanhcam
Copy link
Author

@crynobone This worked. I'll close this issue.

$formData->boolean('is_billing') === true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is required
Projects
None yet
Development

No branches or pull requests

3 participants