Pass your object structure into the schema as an enum via enumOptions #421
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reasons for making this change
To allow easier and more flexible integration into an existing product with a existing object structure.
I coopted the existing variable
enumOptions
and exposed it in the schema. I figured if it was a good enough name internally it's my best bet externally too! But I'm terrible at naming we can call it whatever you want if you like the fix.For example:
Will render the same as:
Hopefully the advantages are obvious. Instead of having to copy another array I can reference directly into an existing schema. In my case a GraphQL schema.
e.g.
Which brings me to the second part of this fix. In my case,
this.props.myarray
is actually a graph returning asynchronously via a promise.When the form is initially rendered the
this.props.myarray
is not set. This will in fact lead toenumOptions
being passed into the Select, Radio or Checkboxes widget as a booleanfalse
.I had hoped to move the fix higher, however doing so seemed to break string fields in the playground, so I've put the check:
In all three of those classes.
Before someone asks I had considered considered using the data and populating a new "translated"
enumOptions
with just two fieldsvalue
andlabel
. It would have been a slightly easier change (not that this is big).However I decided against it for the following reasons. There is no reason why another custom control might not wish to access other data in your structure ... why limit it to two fields?
I can envisage (and will probably implement) a custom array class based on ag-grid. I could then display the entire data in the grid and have checkboxes down the left hand side still for selection. But I could only do that if the data structure is passed completely into the control. Perhaps another case could be another field for a hover tooltip over a selection.
It just seems more flexible. Very interested in general feedback. I understand this is a feature change/request rather than a bugfix and it should be considered carefully before giving green light or it may need rework. I hope though that people like the idea in general.
This (in part) addresses:
#415
Checklist
I've tried every enum I could find in the playground to try and break it.
Variations of:
And:
And:
And: