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

Multiselect #16

Open
stipic opened this issue Dec 1, 2022 · 11 comments
Open

Multiselect #16

stipic opened this issue Dec 1, 2022 · 11 comments

Comments

@stipic
Copy link

stipic commented Dec 1, 2022

Is possible to make EasyMediaField multiselect or atleast can i combine somehow EasyMediaField with CollectionField?

btw. thank you alot for great bundle.

greeting Kristijan

@LiegeoisJules
Copy link

I would also like a feature like this. Is this even possible to combine with a CollectionField ?

thanks for this bundle anyways !

love and peace

@jdadeliom
Copy link
Contributor

Hello, thanks for ou interest in the project.
To use a mediaField with CollectionField, it's possible.

For example

public function configureFields(string $pageName): \Iterator {
    yield CollectionField::new('gallery')
        ->hideOnIndex()
        ->setEntryType(EasyMediaType::class)
        ->allowAdd()
        ->allowDelete()
    ;
}

@treeindark
Copy link

not work ->
js Error : Uncaught TypeError: lastElement is undefined

.field-collection-item is not found

@treeindark
Copy link

treeindark commented Mar 31, 2023

I will add :
<div class="{{ form.vars.ea_crud_form.ea_field.columns ?? form.vars.ea_crud_form.ea_field.defaultColumns ?? 'field-collection-item field-collection-item-complex' }}">

line19 : vendor/agence-adeliom/easy-media-bundle/src/Resources/views/form/easy-media.html.twig

add to Crud:
public function configureAssets(Assets $assets): Assets { return $assets->addJsFile('bundles/easymedia/js/app.js'); }

But

field-collection.c6a8940b.js:1 Uncaught TypeError: Cannot read properties of null (reading 'classList')
    at HTMLButtonElement.<anonymous> (field-collection.c6a8940b.js:1:2418)

drop image, button stay.

on Save
App\Entity\Event::addMedia(): Argument #1 ($media) must be of type App\Entity\EasyMedia\Media, string given, called in /var/www/billeterie/vendor/symfony/property-access/PropertyAccessor.php on line 576

@vlad-ghita
Copy link

I'm seeing same error as @treeindark.

When clicking on + Add new item, it fails b/c lastElement is undefined.

                if (lastElement.querySelectorAll("script").forEach((function(script) {
                    return eval(script.innerHTML)
                }

@NodokaMurmevent
Copy link

NodokaMurmevent commented Apr 27, 2023

hello, it’s not work for me too :

            CollectionField::new('gallery')
            ->hideOnIndex()
            ->setEntryType(EasyMediaType::class)
            ->allowAdd()
            ->allowDelete(),

in my entity :

    #[ORM\OneToMany(mappedBy: 'property', targetEntity: PropertyGallery::class, orphanRemoval: true)]
    private Collection $gallery;

in my gallery entity :

    #[ORM\Column(type: 'easy_media_type',length: 255, nullable: false)]
    private Media|string|null $image = null;

    #[ORM\ManyToOne(inversedBy: 'gallery')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Property $property = null;

when i click on (add) i have this error :
Uncaught TypeError: can't access property "insertAdjacentHTML", collectionItemsWrapper is null
and it’s look like he try to add a div class="ea-form-collection-items" in the div class="ea-form-collection-items"
image

@NodokaMurmevent
Copy link

NodokaMurmevent commented May 4, 2023

bump. Look like it’s corrected, i upgraded to 2.0.94 and all work fine now.

but only if you use :

CollectionField::new('yourField')
->hideOnIndex()
->useEntryCrudForm()->setEntryIsComplex()->renderExpanded()
->allowAdd()
->allowDelete(),

@revolted
Copy link

bump. Look like it’s corrected, i upgraded to 2.0.94 and all work fine now.

but only if you use :

CollectionField::new('yourField')
->hideOnIndex()
->useEntryCrudForm()->setEntryIsComplex()->renderExpanded()
->allowAdd()
->allowDelete(),

@NodokaMurmevent can i ask how you manage to get it working by using the useEntryCrudForm? What does the source of the EntryCrudForm controller look like?
When i basically create a "MediaCrudController" which has an EasyMediaField in it, the add/remove works, but is doesn't properly store the collection of selected files

@NodokaMurmevent
Copy link

NodokaMurmevent commented Sep 15, 2023

can i ask how you manage to get it working by using the useEntryCrudForm? What does the source of the EntryCrudForm controller look like? When i basically create a "MediaCrudController" which has an EasyMediaField in it, the add/remove works, but is doesn't properly store the collection of selected files
@revolted
In my precedent post, I forgot the , cascade:["all"])] there :

    /**
     * @var \Doctrine\Common\Collections\Collection<int, \App\Entity\PropertyGallery>|\App\Entity\PropertyGallery[]
     */
    #[ORM\OneToMany(mappedBy: 'property', targetEntity: PropertyGallery::class, orphanRemoval: true, cascade:["all"])]
    private Collection $gallery;

Have you made the same mistake?

@revolted
Copy link

can i ask how you manage to get it working by using the useEntryCrudForm? What does the source of the EntryCrudForm controller look like? When i basically create a "MediaCrudController" which has an EasyMediaField in it, the add/remove works, but is doesn't properly store the collection of selected files
@revolted
In my precedent post, I forgot the , cascade:["all"])] there :

    /**
     * @var \Doctrine\Common\Collections\Collection<int, \App\Entity\PropertyGallery>|\App\Entity\PropertyGallery[]
     */
    #[ORM\OneToMany(mappedBy: 'property', targetEntity: PropertyGallery::class, orphanRemoval: true, cascade:["all"])]
    private Collection $gallery;

Have you made the same mistake?

Thanks for the reply @NodokaMurmevent
The error was not caused by the cascade option in the entity. The problem is that I only want to show button to add files to the collection, but when using useEntryCrudForm from your example it will display a form with textboxes to add a media entity to the database instead of the gallery button. So I just wondered what your CrudController looks like :)
If I modify the configureFields to only display a single "EasyMediaField" it works, but then the submitted payload it does not match the propertyPaths of my entity anymore, so it won't save properly

     /**
      * the field in my PostCrudController, linked to the Many2Many attachments field
      */
        yield CollectionField::new('attachments')
            ->hideOnIndex()
            ->useEntryCrudForm(AttachmentCrudController::class)->setEntryIsComplex()
            ->renderExpanded()
            ->allowAdd()
            ->allowDelete()
     /**
      * the field in my AttachmentCrudController
      */    
    public function configureFields(string $pageName): iterable
    {
        yield EasyMediaField::new('attachments', 'File')->setVirtual(true);
    }

This will generate a form payload with form['attachments'][0]['attachments'][0] = 24
But ideally it should be something like form['attachments'][0] = 24

@revolted
Copy link

drop image, button stay.

on Save App\Entity\Event::addMedia(): Argument #1 ($media) must be of type App\Entity\EasyMedia\Media, string given, called in /var/www/billeterie/vendor/symfony/property-access/PropertyAccessor.php on line 576

This is because the ModelTransformer in EasyMediaType.php does not return the Media entity.

Works when you override and change Form/EasyMediaType.php (line 88)

return $mediaId;

to

return $media;

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

7 participants