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

dependsOn fields support #4

Closed
chrillep opened this issue Nov 22, 2022 · 9 comments
Closed

dependsOn fields support #4

chrillep opened this issue Nov 22, 2022 · 9 comments

Comments

@chrillep
Copy link
Contributor

chrillep commented Nov 22, 2022

does this package have dependsOn fields support?

https://nova.laravel.com/docs/4.0/resources/fields.html#dependent-fields

we are currently using outl1ne/nova-settings

but having issues with dependsOn fields not working. Or thats not fair. they just havent implemented dependson functionality

ref:

@stepanenko3
Copy link
Owner

Hi, @chrillep

Our package is a wrapper on Nova Resources, that's why everything should work

@chrillep
Copy link
Contributor Author

ok ill try it

@chrillep
Copy link
Contributor Author

chrillep commented Nov 30, 2022

Hey @stepanenko3 !
Tested it, but cant get depends on fields to work :(

in app/Nova/Settings/Demo.php

<?php

declare(strict_types=1);

namespace App\Nova\Settings;

use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\FormData;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Stepanenko3\NovaSettings\Types\AbstractType;

class Demo extends AbstractType
{
    public function fields(): array
    {
        return [
            Boolean::make('Param 1 Show Text Field', 'param_1')
                ->default(true),

            Text::make('Text That Param 1 Depends on', 'param_1_depends_on')
                ->hide()
                ->rules('sometimes')
                ->dependsOn('param_1', function (Text $field, NovaRequest $request, FormData $formData) {
                    if ($formData->param_1 === false) {
                        $field->show()->rules('required');
                    }
                }),
            
            Select::make('Purchase Type', 'type')
                ->options([
                    'personal' => 'Personal',
                    'gift' => 'Gift',
                ]),

            Text::make('Recipient')
                ->readonly()
                ->dependsOn(
                    ['type'],
                    function (Text $field, NovaRequest $request, FormData $formData) {
                        if ($formData->type === 'gift') {
                            $field->readonly(false)->rules(['required', 'email']);
                        }
                    }
                ),
        ];
    }
}

@stepanenko3
Copy link
Owner

@chrillep, thanks
I will try to fix it in some days

@chrillep
Copy link
Contributor Author

@chrillep, thanks I will try to fix it in some days

really like your package tho. its just that depends on opens up alot of good ux for showing/hiding fields while editing :)

@chrillep
Copy link
Contributor Author

@stepanenko3 hey how is it going. Im guessing it is more work than expected (It always is) ;) . Keep up the good work tho!

@stepanenko3
Copy link
Owner

@chrillep, hi
Sorry for long delay
Try this code

Because we are not able to update the attributes of already specified dependsOn, you must specify them explicitly

            Select::make('Purchase Type', 'type')
                ->options([
                    'personal' => 'Personal',
                    'gift' => 'Gift',
                ]),

            Text::make('Recipient')
                ->readonly()
                ->dependsOn(
                    ['settings->type'],
                    function (Text $field, NovaRequest $request, FormData $formData) {
                        if ($formData->{'settings->type'} === 'gift') {
                            $field->readonly(false)->rules(['required', 'email']);
                        }
                    }
                ),

@stepanenko3
Copy link
Owner

@chrillep

https://github.com/stepanenko3/nova-settings#using-dependson-with-out-package

@chrillep
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants