stepanenko3 / nova-settings

This Laravel Nova settings tool based on env, using nativ nova fields and resources
MIT License
31 stars 5 forks source link

dependsOn fields support #4

Closed chrillep closed 1 year ago

chrillep commented 1 year ago

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 commented 1 year ago

Hi, @chrillep

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

chrillep commented 1 year ago

ok ill try it

chrillep commented 1 year ago

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 commented 1 year ago

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

chrillep commented 1 year ago

@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 commented 1 year ago

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

stepanenko3 commented 1 year ago

@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 commented 1 year ago

@chrillep

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

chrillep commented 1 year ago

@chrillep

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

eyyy gr8! ty!