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

The "Add Files" button reset the file selection with the collection upload #166

Open
numerogeek opened this issue Jun 8, 2015 · 3 comments

Comments

@numerogeek
Copy link

Hello,

I am tryin to buid a form that allows user to add an image collection to an entity.

Entity property :

    /**
     * @ORM\OneToMany(targetEntity="PropertyImage", mappedBy="property", orphanRemoval=true, cascade={"persist", "remove"})
     */
    protected $pics;

Entity propertyImage :

    /**
     * @var int
     *
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @Assert\File(
     *     maxSize="20M"
     * )
     * @Vich\UploadableField(mapping="property_file", fileNameProperty="fileName")
     */
    protected $file;

    /**
     * @ORM\Column(name="file_name", type="string", nullable=true)
     */
    protected $fileName;

    /**
     * @ORM\ManyToOne(targetEntity="Property", inversedBy="pics")
     * @ORM\JoinColumn(name="property_id", referencedColumnName="id")
     */
    protected $space;

So I have a formType for property which is :

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            /// ... some property form fields ...
            ->add('pics', 'afe_collection_upload', array(
                'type' => new ImageType(),
                'nameable' => false,
                'allow_add' =>true,
                'maxNumberOfFiles' => 5,
                'options' => array(
                    'data_class' => "AppBundle\Entity\PropertyImage"
                )
            ))
        ;
    }

And the ImageType is basically simple :

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('id')
            ->add('fileName')
            ->add('file')
        ;
    }

And here are the results:

ubuntu

My problem is:
When I click "Add Files" I have a file browser that allow me to select a file, the file shows up, no problem.
But when I click again on Add Files to select a second file, the second file replace the first. instead of adding to the queue :

ubuntu2

The behavior I expect is : when I click on add file, a new row appear to allow me to select an additionnal file. Instead of replacing the first one.

any idea ?

Thanks

@numerogeek
Copy link
Author

ping @loostro

@ioleo
Copy link
Member

ioleo commented Jun 11, 2015

@numerogeek Have you tried selecting multiple files? Does the file input have multiple="multiple" attribute?

@sebastianlp
Copy link

When you are using collection upload with sync mode, the behavior you describe going to happen. You have to configure async upload to achieve what you want.

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

3 participants