ArrayFieldTemplate#437
Conversation
…ropriate props passed into it).
Update fork.
|
Great work! Thanks for the rewrite, this looks really good. 👍 |
|
Thanks @olzraiti! 😄 |
n1k0
left a comment
There was a problem hiding this comment.
This looks great, thank you!
Would you mind adding a few tests covering the custom array field template case?
README.md
Outdated
| - [Form attributes](#form-attributes) | ||
| - [Advanced customization](#advanced-customization) | ||
| - [Field template](#field-template) | ||
| - [Array template](#array-template) |
There was a problem hiding this comment.
Nit: Array field template maybe
README.md
Outdated
| - `index`: number | ||
| - `onDropIndexClick`: (index) => void | ||
| - `onReorderClick`: (index, newIndex) => void | ||
| - `readonly`: boolean |
There was a problem hiding this comment.
General remark for these two lists: it would be nice to have English sentences describing the purpose of each property, for consistency with the rest of the docs :)
There was a problem hiding this comment.
Good idea! I'll improve the docs I wrote a bit!
playground/samples/customArray.js
Outdated
| @@ -0,0 +1,38 @@ | |||
| import React, { Component } from "react"; | |||
|
|
|||
| const ArrayFieldTemplate = props => ( | |||
There was a problem hiding this comment.
Please use a regular function declaration here, for consistency with the rest of the code in this project.
playground/samples/index.js
Outdated
| }; | ||
| Single: single, | ||
| "Custom Array": customArray | ||
| }; No newline at end of file |
There was a problem hiding this comment.
Nit: all files need an empty line at EOF.
| <div className="field-description" key={`field-description-${props.idSchema.$id}`}> | ||
| {props.schema.description} | ||
| </div> | ||
| ) : null} |
There was a problem hiding this comment.
Nit: We're using either the foo && <Bar/> or foo ? <Bar/> : null checks, we should decide for one single style and use it consistently across the project. I don't have a strong opinion on which one is better, though I like the concision of the && version.
Note that if we go with the latter, this will have to be submitted in a followup PR to avoid cluttering this one, which is large enough already.
There was a problem hiding this comment.
I also prefer using && for brevity. I'll hold off on this change though, like you said.
src/components/fields/ArrayField.js
Outdated
|
|
||
| <div className="row array-item-list" | ||
| key={`array-item-list-${props.idSchema.$id}`}> | ||
| {props.items && props.items.map(p => DefaultArrayItem(p))} |
There was a problem hiding this comment.
Nit: I'm curious as to if props.items.map(DefaultArrayItem) would work here.
There was a problem hiding this comment.
Good catch! That should work. I'll test it out, and update accordingly.
| if (event) { | ||
| event.preventDefault(); | ||
| event.target.blur(); | ||
| } |
There was a problem hiding this comment.
I'm curious as to why this is needed? Test env?
There was a problem hiding this comment.
I added this so that you could programmatically call the onDropIndexClick()() without a MouseEvent argument.
|
Thanks for the comments! I'll get those changes in, plus those tests :) |
|
Hey @n1k0, I just addressed the comments you made. Let me know if there's anything else you'd like changed! Thanks! |
n1k0
left a comment
There was a problem hiding this comment.
A few nits in tests and we're good to go.
test/ArrayFieldTemplate_test.js
Outdated
| items: {type: "string"} | ||
| }; | ||
|
|
||
| const {node} = createFormComponent({ |
There was a problem hiding this comment.
Please move this to a beforeEach statement, so the element is not created as soon as the describe call is executed. Created troubles in the past. Please refer to existing tests to see how it's done.
| ArrayFieldTemplate, | ||
| formData, | ||
| schema | ||
| }); |
|
Appreciate the feedback @n1k0 👍 |
|
This is a very nice feature, thanks for the great work on this. |
|
Of course! Thanks to you and your team for a great library! |
Breaking changes When a text input is emptied by the user, it's value is now reset to `undefined` instead of being set to `""` (empty string) as previously. This better matches traditional HTML forms behavior. New features * Add an array field template component (#437) * Wrap radio and checkbox labels into span to enable styling. (#428) * Reset text inputs value when emptied (#442) * Add transform hook for changing errors from json schema validation (#432) * Add a noHtml5Validate prop (#448) * Add support for a onBlur event handler (#431) * Allow empty option for enum fields (#451) Bugfixes * Fix #452: Support recursively referenced definitions. (#453) * Fix #454: Document what master actually is, suffix its version with -dev.
|
Released in v0.42.0. |
|
@dehli Any chance you can rehost the playground. I am not 100% sure this is the functionality I am looking for |
|
Hey @Vaibhav430, the official playground contains what I had hosted. Just click on |
Reasons for making this change
Hello again! I've decided to create a new PR since I changed how the custom arrays were implemented based on feedback on my last PR (#395). Sorry it took a while!
With this change, you can customize how your arrays are rendered by passing an
ArrayFieldTemplateobject, very similar to theFieldTemplate.I'd love some feedback! My initial thoughts are that I'd rather pass
removeItem,moveItemDown, andmoveItemUpto each item in the array (so that you don't need to pass the index to the functions). The root array could then store the existing functions that take indices.This PR is related to #354 and will make the library much more flexible.
Here's the playground so you can see what it looks like!
Thanks!
Edit: I'll get that test passing. Forgot to run that!Checklist