json-editor icon indicating copy to clipboard operation
json-editor copied to clipboard

Delete Property

Open kane-mason opened this issue 3 years ago • 15 comments

General information

  • json-editor version: 2.5.4

Expected behavior

An easy way to delete a property or property value.

For example see link below. In our case this has become more noticeable when using format: file, once you select a photo/picture and save, there is then no easy way to delete the image you uploaded, you need to actually edit the json and remove the base64 contents, which is of course cumbersome. This could apply to any proprty, not just format: file, I think a simple x or delete options like are available for arrays would be useful, or perhaps configurable per property.

Actual behavior

You are unable to delete easilly.

Steps to reproduce the behavior

Direct link to example: https://json-editor.github.io/json-editor/?data=N4Ig9gDgLglmB2BnEAuUMDGCA2MBGqIAZglAIYDuApomALZUCsIANOHgFZUZQD62ZAJ5gArlELwwAJzplsrEIgwALKrNShYUbFUIAFKlNrwFUQRF0p2XHgqlUAjiJj2AJqgDaIeGQYKIUmBEMDq8EJggALpsAZCGsDQa3r6WmuaWilBSMPAA5gquNBjZ0HAmVgBiLohQAARk8K61ADJkNbU+fmx0Oc1UeVDKqAAsbIVEZCLY4lYAUoZqgrUAItImAL4xgcGh4RhJJDJkM8Qhut1UrjBkSXg5ZFKCAKLwWFd5hHhtVABswyCbEBmCyEGrZD7rSFsRDKMAUXiGQJGQg5KCGMg8MqmVR+Kx4MBgKBgsgQf6QoA=

{
  "title": "Person",
  "type": "object",
  "required": [
    "name",
    "profile_pic"
  ],
  "properties": {
    "name": {
      "type": "string",
      "description": "First and Last name",
      "minLength": 4,
      "default": "Jeremy Dorn"
    },
    "profile_pic": {
      "format": "file",
      "media": {
        "binaryEncoding": "base64"
      },
      "type": "string"
    }
  }
}

kane-mason avatar Aug 09 '21 17:08 kane-mason

I have been looking for this for a long time. Hope this gets fixed soon.

ikushum avatar Aug 13 '21 07:08 ikushum

PRs welcome

schmunk42 avatar Aug 16 '21 09:08 schmunk42

@bhagyamudgal no objections from me

kane-mason avatar Aug 29 '21 14:08 kane-mason

@kane-mason just a general question: why is profile_pic required when you can (should be able to) delete it?

But a PR would be nice anyway.

schmunk42 avatar Aug 30 '21 08:08 schmunk42

@schmunk42 it is not atually required, was just for visiblity on the test case

kane-mason avatar Sep 13 '21 19:09 kane-mason

@kane-mason Because with show_opt_in and required: false you could achieve a similar behaviour.

schmunk42 avatar Sep 14 '21 12:09 schmunk42

@schmunk42 i did not know that! Thanks!

kane-mason avatar Sep 14 '21 12:09 kane-mason

@schmunk42 following on your comment, is there a way to display certain properties that are not necessarilly required? show_opt_in shows all non-required properties, i am looking for a way to show certain ones

kane-mason avatar Sep 21 '21 18:09 kane-mason

This is a logical problem with json-schema, IMO.

Eg.

  • how would you display an empty string and which json should be generated (empty string or nothing)?
  • how would you display an empty integer without default value (0, empty string, nothing)?

schmunk42 avatar Sep 22 '21 12:09 schmunk42

@schmunk42 is this not similar to show_opt_in? How does that do it?

Just to make sure we on the same page my idea is, like the required array, to have an optional (can be named more appropriately) array.

In the way I, and im sure others use this package, is like a form to capture information. Like many forms some fields are required and some not, but i still want the optional fields to be displayed and up to the user to fill in or not. However i do not want to display allll non required fields as some are not meant to be visible to user, etc timestamps and other generated information.

kane-mason avatar Oct 10 '21 19:10 kane-mason

I made an example with show_opt_in set to true, required, optional, hidden and visible properties that could answer your question: example

germanbisurgi avatar Oct 11 '21 07:10 germanbisurgi

@germanbisurgi @schmunk42 that is very useful, thanks!

The only problem (and it might be a bug?) is that there is no way to unhide the properties in the ui? If you click the properties dropdown, the hidden properties are selected (should be unselected maybe?) and toggling that box has no effect. Maybe i am misunderstanding but would be nice to show the hidden properties in the ui if you need to

kane-mason avatar Oct 13 '21 19:10 kane-mason

@kane-mason Actually I thought hidden properties in the example are hidden-inputs, but they are just hidden by CSS. So you could make them visible, but I think they shold be type="hidden".

Not sure how to proceed here. CC: @germanbisurgi

schmunk42 avatar Oct 14 '21 11:10 schmunk42

You can set the editor's "format": "hidden" to render inputs type hidden like in this updated example

I think that we are discussing something totally different that the original topic :-)

germanbisurgi avatar Oct 14 '21 12:10 germanbisurgi

Created a separate issue for our discussion.

kane-mason avatar Oct 14 '21 19:10 kane-mason