symfony2admingenerator / AvocodeFormExtensionsBundle

(old-legacy) Symfony2 form extensions for Admingenerator project (also working standalone!)
Other
48 stars 31 forks source link

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

Open numerogeek opened 9 years ago

numerogeek commented 9 years ago

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 commented 9 years ago

ping @loostro

ioleo commented 9 years ago

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

sebastianlp commented 9 years ago

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.