formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

Cannot Drag custom components

Open 152hq opened this issue 8 years ago • 13 comments

Hi,

We are trying to create custom components and find the components created cannot be dragged.

Steps to re-create

  1. http://formio.github.io/formio.js/app/examples/customcomponent.html
  2. Try creating 2 check box components
  3. Try dragging one on top of other
  4. Builder will show the change, but render component does not show the change
  5. In the image below, the render and builder component shows different component order

image

What is happening in WebFromBuilder.js ln: 938 if (element.component) returns as null for a custom component upon drag after initial setup.

Please help. Thanks

152hq avatar Nov 29 '18 06:11 152hq

This is working for me... Please provide a jsfiddle of the problem.

travist avatar Nov 29 '18 15:11 travist

Hi,

Please find the fiddle below

http://jsfiddle.net/152hq/rj8403d9/3/

Steps

  1. First create a 2x2 matrix checkbox
  2. Then create a 1x1 matrix chechbox
  3. trying moving 1x1 matrix to the top
  4. The builder component will show the dragged object, while the Rendered Form will not. (check the console and you will see a warning "No element.id defined for dropping")

image

152hq avatar Nov 29 '18 22:11 152hq

Looks like there is a missing event when dragging the custom component. If you edit one of the components it updates and fixes.

randallknutson avatar Dec 03 '18 15:12 randallknutson

yes, but if a form has custom components, it really affects the layout . Is there a fix for this? We have worked out a solution by appending the below code as last line in the build function to fix this. Please let us know if there be a better solution

this.element.component = this;

Thanks

152hq avatar Dec 03 '18 22:12 152hq

Can you create a pull request with this fix in place so that it works for everyone else?

travist avatar Dec 10 '18 17:12 travist

Sure, will do. Do we include checkbox matrix component?

152hq avatar Dec 10 '18 22:12 152hq

No, don't include the checkmatrix component in your pull request.

travist avatar Dec 17 '18 15:12 travist

but, this is something which needs to be addressed while creating a custom component, how do I go with that then?

152hq avatar Dec 18 '18 22:12 152hq

I think that this change should be included in the core library so that any other custom component created would have this set and then not be required to set it within the custom component itself. Is there not a way to provide the code you did above to the point after the component is created?

travist avatar Dec 19 '18 15:12 travist

yep, working on your point. Will update with possible solution asap.

152hq avatar Dec 19 '18 22:12 152hq

You must set an Id for first tag in custom component. like this

CheckMatrixComponent.prototype.build = function () {

    this.element = this.ce('div', {
        class: 'table-responsive'
    });

//for all CheckMatrixComponents need unique id like "testid"

    this.element.setAttribute('id', 'testid');

//some code

    this.element.component = this;

};

amir135 avatar Sep 26 '19 11:09 amir135

Hello! Anyone know why https://formio.github.io/formio.js/app/builder PDF builder does not work? Drag and dropping fields not working this is only happening for Chrome on MAC.

mujtaba1016 avatar Sep 07 '20 17:09 mujtaba1016

@mujtaba1016,

We will take a look and see why this is happening. We created a ticket and have added it to our backlog. We welcome a PR or have a process to expedite this issue. For reference, the ticket number is PDF-159.

We will let you know once this issue has been resolved.

wag110894 avatar Sep 14 '20 15:09 wag110894