jsoneditor icon indicating copy to clipboard operation
jsoneditor copied to clipboard

Restrict drag to inside properties array only

Open AlenKelemen opened this issue 6 years ago • 13 comments

I need to allow user to arrange order of properties just inside one array but prevent dragging to another node. Is there a way to accomplish this ? I used validation with no problem, but preventing would be more user frendly. On pic example, one layers property is dragged outside layers array to root, that is what I want to prevent and restrict dragging only to layers array.

Capture

AlenKelemen avatar Apr 16 '20 09:04 AlenKelemen

That is an interesting idea, I see what you mean.

Thinking aloud here: I think this should be a configuration option, since this restriction is not always what you want. Or would it make sense to, say, when dragging, restrict dragging outside by default, and when having the Ctrl key down, allow dragging outside?

josdejong avatar Apr 19 '20 07:04 josdejong

Maybe to link restriction to json schema ?

AlenKelemen avatar Apr 19 '20 12:04 AlenKelemen

That's a good idea!

We could implement the following behavior:

  • Create an option "dragInsideOnly", which can be set to true, false
  • When the option is not specified, limit dragging to inside only when a JSON schema is defined, and do not limit dragging otherwise

josdejong avatar Apr 19 '20 18:04 josdejong

Anyone interested in implemented this feature?

josdejong avatar May 07 '20 16:05 josdejong

+1

AlenKelemen avatar May 07 '20 20:05 AlenKelemen

Just a small note that It would be nice to have ability to restrict drag of elements in current level no matter if it's elements inside of array or objects inside of parent object. I'm really suffering from it as in my current project I need somehow to prevent drag of child objects to top level.

keshon avatar May 23 '20 20:05 keshon

I just had a short look at the code, and it turns out this is quite easy to implement. Working on it.

josdejong avatar May 24 '20 12:05 josdejong

I've published this new option limitDragging in v9.0.0.

@keshon and @AlenKelemen can you give it a try?

josdejong avatar May 24 '20 14:05 josdejong

I've published this new option limitDragging in v9.0.0.

@keshon and @AlenKelemen can you give it a try?

@josdejong I tested and it works great. Thank you very much!

keshon avatar May 25 '20 10:05 keshon

Heads up that limitDragging is not declared in the type file so it can't be used when using typescript

gigiskarlett avatar Sep 29 '21 21:09 gigiskarlett

so it can't be used when using typescript

@gigiskarlett you can always work around that with @ts-ignore or something like that.

It would be great if you or someone else can create a PR at DefinitelyTyped to add this missing option limitDragging in the TypeScript definitions. Anyone able to help out?

josdejong avatar Oct 02 '21 07:10 josdejong

so it can't be used when using typescript

@gigiskarlett you can always work around that with @ts-ignore or something like that.

It would be great if you or someone else can create a PR at DefinitelyTyped to add this missing option limitDragging in the TypeScript definitions. Anyone able to help out?

I added the type definition to DefinitelyTyped and it has been merged so this shouldn't be a problem moving forward. Thanks for doing this library 🙏🏽

gigiskarlett avatar Oct 02 '21 16:10 gigiskarlett

Heee that's awesome, thanks Gigi 👍

josdejong avatar Oct 02 '21 19:10 josdejong