1

All the Upload examples show using NativeButton when programmatically creating an Upload. I want to use a Button (vaadin-button) that is part of a Designer layout. When I try this I see the following error:

Caused by: java.lang.IllegalArgumentException: Trying to detach an element from parent that does not have it.
    at com.vaadin.flow.dom.impl.AbstractNodeStateProvider.removeChild(AbstractNodeStateProvider.java:123)
    at com.vaadin.flow.dom.Node.removeChild(Node.java:376)
    at com.vaadin.flow.dom.Element.removeFromParent(Element.java:577)
    at com.vaadin.flow.dom.Node.insertChild(Node.java:293)
    at com.vaadin.flow.dom.Node.appendChild(Node.java:141)
    at com.vaadin.flow.component.upload.GeneratedVaadinUpload.addToAddButton(GeneratedVaadinUpload.java:1344)
    at com.vaadin.flow.component.upload.Upload.setUploadButton(Upload.java:276)

We are using Vaadin 14 in CDI mode.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
tstiemer
  • 110
  • 8
  • Can you provide a little bit more context (code)? As a sanity-check, I tried the [Custom components upload](https://vaadin.com/components/vaadin-upload/java-examples) example with 14.6.1, and just swapping `NativeButton` to `Button` works fine in that limited example. I probably did not quite understand your situation. – Marc Englund May 21 '21 at 11:28
  • It works if I create the vaadin Button programmatically, but not if the button is created by designer in the .js file. – tstiemer May 25 '21 at 15:58

2 Answers2

2

To change the upload button with Designer, you need to drag the button into the upload in the hierarchy, then add slot="add-button" attribute.

Your templates should end up looking like this:

<vaadin-upload>
 <vaadin-button slot="add-button">
   Button 
 </vaadin-button>
</vaadin-upload>

Note that you must do this in the hierarchy panel. enter image description here

If this does not help (maybe you did this already), could you perhaps include some code that shows what you are trying to do?

Marc Englund
  • 451
  • 4
  • 4
0

I've just created an issue for this improvement in our Designer repository https://github.com/vaadin/designer/issues/2399.

Feel free to comment.

szolo
  • 247
  • 1
  • 4
  • 15