Muetze42 / nova-radio-field

A Radio Buttons field for Laravel Nova.
https://novapackages.com/packages/norman-huth/nova-radio-field
MIT License
5 stars 2 forks source link

DependsOn #7

Closed CodeWithDennis closed 1 year ago

CodeWithDennis commented 1 year ago

It seems like this field is not compatible with dependsOn. https://nova.laravel.com/docs/4.0/resources/fields.html#dependent-fields

Is it possible to make this compatible?

Muetze42 commented 1 year ago

Is it not compatible? That's too bad. I haven't even looked at dependsOn yet and assumed that any field would work as long as you stick to the docs.

Of course I will have a look at it.

CodeWithDennis commented 1 year ago

Hi, i've added a small clip https://user-images.githubusercontent.com/23448484/235164981-eaea046d-f893-4d9a-93ea-5726721d0f72.mov

Would appreciate it!

Muetze42 commented 1 year ago

There is really a DependentFormField mixin wich must used. Good, now that I know this, I can think of it right from the beginning when I create a field.

The dependsOn method is available as of the current release.

salmanhijazi commented 1 year ago

Hello. DependsOn generally works well. But when used in conjunction with NovaJson, it doesn't work. So if a field DependsOn a Radio field, the Radio field only sends the first option as the value. Example below:

JSON::make('Wrapper', 'wrapper', [

    Radio::make('Alpha', 'alpha')->options([
            'yes' => 'Yes',
            'no' => 'No'
        ])
        ->default('no'),

        Radio::make('Beta', 'beta')->options([
            'yes' => 'Yes',
            'no' => 'No'
        ])
        ->hide()
        ->rules('required_if:alpha,yes')
        ->dependsOn('wrapper->alpha', function (Radio $field, NovaRequest $request, FormData $data) {
            if($data['wrapper->alpha'] == 'yes')
                $field->show();
        }),

])

In this case, "alpha" will always return the value "yes", irrespective of the selection in the form.

Cheers

Muetze42 commented 1 year ago

Sorry. The system NVMe failed on my laptop. I'll take a look at it during the week.