default value does not work
See original GitHub issue{
  "title": "Person",
  "type": "object",
  "properties": {
    "Do you have any pets?": {
      "type": "string",
      "enum": [
        "No",
        "Yes: One",
        "Yes: More than one"
      ],
      "default": "No"
    }
  },
  "required": [
    "Do you have any pets?"
  ],
  "dependencies": {
    "Do you have any pets?": {
      "oneOf": [
        {
          "properties": {
            "Do you have any pets?": {
              "enum": [
                "No"
              ]
            }
          }
        },
        {
          "properties": {
            "Do you have any pets?": {
              "enum": [
                "Yes: One"
              ]
            },
            "How old is your pet?": {
              "type": "number"
            }
          },
          "required": [
            "How old is your pet?"
          ]
        },
        {
          "properties": {
            "Do you have any pets?": {
              "enum": [
                "Yes: More than one"
              ]
            },
            "Do you want to get rid of any?": {
              "type": "boolean",
              **"default": false;**
            }
          },
          "required": [
            "Do you want to get rid of any?"
          ]
        }
      ]
    }
  }
}
as shown in the code, the default value for “Do you want to get rid of any?” does not work!
Issue Analytics
- State:
 - Created 5 years ago
 - Comments:11 (4 by maintainers)
 
Top Results From Across the Web
c# - DefaultValue attribute is not working with my Auto Property
The DefaultValue attribute is only used to tell the Visual Studio Designers (for example when designing a form) what the default value of...
Read more >Solved: Default Value is not working well with Variables
Solved: I a Number field named "ScoreGreenPoint" + a Button named "+Green".. the scenario is that when i click on the.
Read more >Default Values Not Working in Forms - WordPress.org
Hello. How does default values work in UM? As they doesn't seem to work as in any other non-UM forms, or they're not...
Read more >SWITCH default value not working - Microsoft Power BI ...
Solved: Hi everyone, I've been using SWITCH for my report but my issue is that its default value was not showing at all...
Read more >Set default value business rule not working
Use Set Field Value instead of Set Default Value. That should fix the problem. Sam. Reply.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

my guess is that OP is running into the same problem i am. if the initial formData contains any value other than
undefinedfor a property (likenull), default will be ignored.that’s correct, but unexpected, especially when dealing with non-required fields.
IMO – null for non-required fields should be stripped and not fail validation, since there is no way for an end-user to enter a value of
null.json schema supports multiple types e.g.
something: { type: [ 'string', 'null' ] }. if this lib supported that, this would be a non-issue.but as it stands right now, you need to preprocess data and strip all null values before handing it off to jsonschema-form or else it’ll force your user to interact with a non-required field.
An example for https://mozilla-services.github.io/react-jsonschema-form/
formData
With that, there is no way to submit the form.
This uischema doesn’t help matters either:
{ "notrequired": { "ui:emptyValue": "" } }@epicfaace I’ve now added this as a new issue with an example as requested: https://github.com/mozilla-services/react-jsonschema-form/issues/1293