-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default value does not work #975
Comments
Hi @KunWangV , You have a typo in your schema definition the character
Copy and paste that on https://mozilla-services.github.io/react-jsonschema-form/ , it works. Regards |
I cannot get the expected result using your code, are you sure it is ok? |
my guess is that OP is running into the same problem i am. if the initial formData contains any value other than 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 json schema supports multiple types e.g. 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/ {
"type": "object",
"properties": {
"notrequired": {
"type": "string",
"title": "Not required",
"minLength": 0,
"default": "fdsa"
}
}
} formData {
"notrequired": null
} With that, there is no way to submit the form. This uischema doesn't help matters either: |
Any updates here? I have a complex form that starts with a single drop down box. The form is populated based off of what is selected using the dependencies. I have several default values that need to be pre-populated. Anyone know how to get the default value to work here? |
I think this issue is not really coherent so I'm going to close it. As mentioned by @doncesarts, when I fix the typo in the JSON schema, it seems to work OK (an empty @cmawhorter: default values aren't applied when existing values are present. Yes, that includes null, false, empty arrays, or any other JSON-allowed value. I don't really expect that behavior to change. rjsf generally doesn't try to "clean" data. @jduncanRadBlue, if your issue is not addressed by the above remarks, maybe it would be better to open a new issue. |
@glasserc The change @doncesarts mentioned does not work. I copy the typo-less schema into the live editor and hit submit and result: I'm not talking about sanitizing the data as much as I'm talking about a limitation in this lib that can't be worked around. Getting back to the pets schema. The default value for "Do you have any pets?" is pointless because it's impossible to ever use it (as far as rjsf is concerned). |
@glasserc The change @doncesarts mentioned does not work for me either. The part that I'm concerned with is the dependencies. I need to be able to specify default values for those fields. I am not able to get those default values to render. |
@cmawhorter I just tried pasting the typo-less schema into the playground and replacing the
Clicking @jduncanRadBlue Here is the same pet schema with a schema dependency on the field which has a default as well as providing a default.
Replacing the
As previously mentioned, since this issue doesn't really make sense, please feel free to open a new one. |
@glasserc I seem to have a similar example, but I'm unable to make the dependent properties show with the default values. Can you let me know if this is due to an issue with the react-jsonschema-form or with my schema? Specifically, the below can be parsed in the PlayGround. Upon selecting Configuration Mode to be "Simple", I'd expect the default value of "Bit-rate standard" to be 250000 (i.e. 250K) - but it's simply the first entry in the available list. Further, no value is added to the formData until I manually select another value for "Bit-rate standard". Any thoughts/inputs would be appreciated,
|
@MatinF thanks for your report, it does seem to be an issue with using |
@epicfaace I've now added this as a new issue with an example as requested: |
as shown in the code, the default value for "Do you want to get rid of any?" does not work!
The text was updated successfully, but these errors were encountered: