question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

default values for each of the oneOf options are not displayed

See original GitHub issue

General information

When a property is set as oneOf and each of the value option sets a default value, json-editor shows empty values either for the default option or switching to alternative options. Basically the default value settings are not used at all when oneOf is set.

Additionally, the title of the item is also fixed as the JSON key name, rather than using the title field of the property.

See below direct link to example

  • json-editor version: 2.6.1

Expected behavior

for the default option (“string”), display the string-type default value “DP”, when switching to “integer”, sets to 5 instead

Actual behavior

choosing either option, the default value stays at empty

Steps to reproduce the behavior

Direct link to example

{
  "title": "MCX JSON Input",
  "type": "object",
  "required": [
    "SaveDataMask"
  ],
  "format": "categories",
  "properties": {
    "SaveDataMask": {
      "oneOf": [
        {
          "title": "Save detected photon flags",
          "type": "string",
          "default": "DP"
        },
        {
          "title": "Save detected photon flags",
          "type": "integer",
          "default": 5,
          "minimum": 0
        }
      ]
    }
  }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
fangqcommented, Mar 5, 2022

on a side note - we wrote a web-GUI for a cloud-computing based simulator, where JSON editor was a key component in the frontend. This work was was recently published at https://doi.org/10.1117/1.JBO.27.8.083008, where we referenced the json-editor project. here is our web GUI: http://mcx.space/cloud/

json-editor really made our development much simpler, we want to thank the developers for your great works!

0reactions
tobiaseisenschenkcommented, Sep 29, 2022

Thank you for the detailed response. I am using workaround no 1, because of a related issue. I choose a subschema in a anyOf and would like the defaults to be overwritten. As this does not work (it only overwrites changing properties) I can use your hack to force an initial selection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default value not displayed in "Select List" field with two contexts
Hi,. This seems to be a bug with JIRA: I added 2 "Select List" custom fields to the "Resolve Issue" screen for a...
Read more >
reactjs - MUI Object in Select default value not showing but ...
The easiest way to use Select is for your value to be a string and your options to each have a label and...
Read more >
select-options default values - SAP Community
Hi. To assign default values to a selection criterion, you use the following syntax: SELECT-OPTIONS <seltab> FOR <f> DEFAULT <g> [TO <h>] ....
Read more >
3 Ways to Set Default Value in JavaScript | SamanthaMing.com
The better solution with ES6 Default Parameters. function(name = 'no name') { } · Logical Operator ||. This is great if you want...
Read more >
Setting the Yes/No field's default value to None - ServiceNow
Hi Team, I have a catalog item with Yes/No as one of the field type. For this field we have also enabled 'Include...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found