-
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
Add NullField #1238
Add NullField #1238
Conversation
@faissalMT , thanks for the PR. In #1232, you mention that null fields should render the title only and not the input box -- but this PR makes null fields render nothing entirely. Was this intentional? Additionally, I'm wondering how this change plays with the changes done in #1213. If this PR makes it such that "null" fields render nothing, then will our current handling of nullable types be unintuitive? (#1213 makes a field with type Maybe this isn't really a concern though so I'd like to hear your thoughts @faissalMT @warrenseymour |
@epicfaace I've not taken the time to clone this locally and experiment, but as far as I can tell, from a code perspective, this shouldn't clash with what I did in #1213, since that does a reasonably extensive check that the field type is From a UX perspective, however, I agree that explicitly adding a Finally, trying to infer/envisage a legitimate use-case for this I looked at a commit that @faissalMT cited in #1232. It looks as if he's just trying to render a piece of inert content in the form. Would a |
RJSF itself is taking care of handling the rendering of those things (as per the playground example I added), so there was no need for me to implement it explicitly. @warrenseymour
I would expect any native JSON schema type to be renderable by RJSF, if the user doesn't like the handling they can always override it. I think this makes the most sense and is significantly better than an error.
In that project we have a certain level of preprocessing that generates a uiSchema, however we must provide it with a non-null type at the moment or RJSF will refuse to render our custom widget. This also works well for creating placeholder fields. |
@faissalMT thanks, I didn't realize that it was rendering the title/description as well. It makes sense how rjsf should have some kind of default widget for null types. However, my primary concern is this: when you make a field such as What if we make Perhaps the solution for this is to make sure that a I don't know if, as @warrenseymour noted, this entirely fits the use case to "render a piece of inert content in the form". Do we want to clutter our formData by adding in extra null keys when we just want to add in additional content in the form? Perhaps the real solution fo this is in the uiSchema. |
I like this solution and have committed it. An alternative could also simply be to use a default value, but that seems more tacky to me.
I feel like modifying uiSchema to work with non-existent fields as if they are existing fields could quickly get ugly. The uiSchema may serve to further expand on the details of this content (such as use of a custom widget etc), but items in the uiSchema should always correspond to a real field or I believe some fundamental assumptions this project has made are broken. |
src/components/fields/NullField.js
Outdated
import PropTypes from "prop-types"; | ||
|
||
class NullField extends Component { | ||
componentWillMount() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you did this in componentWillMount instead of componentDidMount?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just forgot it was deprecated
src/components/fields/NullField.js
Outdated
|
||
class NullField extends Component { | ||
componentDidMount() { | ||
this.props.onChange(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be better to call onChange only if props.value === undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, that behaviour might come in handy.
Is there anything blocking a review? |
@faissalMT there's just one thing, thanks for the reminder. I was hesitant to merge this because unlike other widgets, this is the only widget that automatically mutates the formData without any user input (by calling |
@epicfaace The system doesn't really have anything that would distinguish between actors and this is a really simple manipulation so I don't think there'll be any issues. |
Okay, thanks. What do you mean by "the system doesn't really have anything that would distinguish between actors"? |
@epicfaace I mean that nothing outside the widgets themselves in RJSF has implemented any assumptions about what kind of actor is entering the data (although they may have been programmed with that assumption), there would be nothing preventing a widget being set by fetched data for example. Our project currently implements a number of automatically generated fields and it really isn't an issue for individual widgets acting on their own data. RJSF only cares about which widget is entering the data for which form field, and we're not breaking the assumption that a widget will only change the data of its field. |
Sounds good, thanks for the explanation. |
Should |
@epicfaace I didn't realise we had a central proptypes object for fields, I've changed it now. |
Thanks! Looks good. |
@glasserc When will this changes be released? |
@epicfaace Will this PR eventually be merged or will the issue with null as default value be resolved in an entirely different way? |
@rmdevos this PR has already been merged -- however, it only addresses fields with |
Reasons for making this change
The JSON Schema type 'null' is currently validated and inferred as a type but shows an error when trying to render. This corrects the issue such that null fields will render nothing, allowing for things like additional help text or use as a temporary placeholder field.
#1232
Checklist
npm run cs-format
on my branch to conform my code to prettier coding style