Skip to content

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

Description

@numerogeek

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions