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

Advanced Nova Media Library field still required even when it's not shown. #12

Open
riptin opened this issue Nov 4, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@riptin
Copy link

riptin commented Nov 4, 2022

As the title says. I want my Images fields to be required but only when it is shown by dependency container. Right now it throws an error when submitting, because some fields are hidden and are still required.

Edit: I use rules('required') because required() doesn't work.

@alexwenzel
Copy link
Owner

Hi @riptin

I use aqjw/nova-medialibrary-field within my test setup and have the following rescource:

public function fields(NovaRequest $request)
{
    return [
        ID::make()->sortable(),

        Medialibrary::make('Image 1', 'collection1')
            ->required()->rules('required', 'min:2')
            ->autouploading(),

        Text::make("value1")->required()->rules('required'),

        Select::make('selection')
            ->options([0, 1, 2]),

        DependencyContainer::make([
            Text::make("value2")->required()->rules('required'),
            Medialibrary::make('Image 2', 'collection2')
                ->required()->rules('required', 'min:2')
                ->autouploading(),
            Select::make('selection2')
                ->options([0, 1, 2]),

            DependencyContainer::make([
                Text::make("value3")->required()->rules('required'),
                Medialibrary::make('Image 3', 'collection3')
                    ->single()
                    ->required()->rules('required')
                    ->autouploading(),

            ])->dependsOn("selection2", 2),

        ])->dependsOn("selection", 1),
    ];
}

and for me the behaviour is the following:

  • if child fields are visible, ALL rules from child fields apply
  • if child field are not visible, rules are ignored

image

@alexwenzel alexwenzel added the bug Something isn't working label Nov 9, 2022
@riptin
Copy link
Author

riptin commented Nov 10, 2022

Hi @alexwenzel, thanks for the reply.
Yeah, I expected similar behaviour, but in my case it's throwning an error as both fields are still required.
To be more specific: I'm using ebess/advanced-nova-media-library. Here is my resoure (I removed extra fields for clarity).

use Ebess\AdvancedNovaMediaLibrary\Fields\Images;

public function fields(NovaRequest $request)
{
  return [
    Boolean::make('Finished'),
    DependencyContainer::make([
      Images::make('Cover Image', 'cover_image')
        ->croppable(false)
        ->conversionOnForm('compressed')
        ->rules('required')
      ])->dependsOn('finished', 1),
    DependencyContainer::make([
      Images::make('Images', 'gallery_images')
        ->croppable(false)
        ->rules('required'),
    ])->dependsOn('finished', 0)
  ];
}

Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants