-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Separate templates and allow a completely custom UI components #1013
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
Changes from all commits
838ef01
adde800
50f20da
af03462
683f073
c37e850
8c59b3c
7180a69
1bb2f9c
e598a23
9df47ad
f37be97
a573096
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ build | |
dist | ||
lib | ||
yarn.lock | ||
.vscode | ||
.directory |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import { default as DefaultErrorList } from "./ErrorList"; | ||
import { | ||
getDefaultFormState, | ||
retrieveSchema, | ||
shouldRender, | ||
toIdSchema, | ||
setState, | ||
getDefaultRegistry, | ||
} from "../utils"; | ||
import validateFormData, { toErrorList } from "../validate"; | ||
|
||
|
@@ -19,7 +17,6 @@ export default class Form extends Component { | |
liveValidate: false, | ||
safeRenderCompletion: false, | ||
noHtml5Validate: false, | ||
ErrorList: DefaultErrorList, | ||
}; | ||
|
||
constructor(props) { | ||
|
@@ -82,13 +79,13 @@ export default class Form extends Component { | |
); | ||
} | ||
|
||
renderErrors() { | ||
renderErrors(ErrorListTemplate) { | ||
const { errors, errorSchema, schema, uiSchema } = this.state; | ||
const { ErrorList, showErrorList, formContext } = this.props; | ||
const { showErrorList, formContext } = this.props; | ||
|
||
if (errors.length && showErrorList != false) { | ||
return ( | ||
<ErrorList | ||
<ErrorListTemplate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need to be a parameter now instead of coming from props? |
||
errors={errors} | ||
errorSchema={errorSchema} | ||
schema={schema} | ||
|
@@ -157,15 +154,10 @@ export default class Form extends Component { | |
}; | ||
|
||
getRegistry() { | ||
// For BC, accept passed SchemaField and TitleField props and pass them to | ||
// the "fields" registry one. | ||
const { fields, widgets } = getDefaultRegistry(); | ||
return { | ||
fields: { ...fields, ...this.props.fields }, | ||
widgets: { ...widgets, ...this.props.widgets }, | ||
ArrayFieldTemplate: this.props.ArrayFieldTemplate, | ||
ObjectFieldTemplate: this.props.ObjectFieldTemplate, | ||
FieldTemplate: this.props.FieldTemplate, | ||
fields: this.props.fields, | ||
widgets: this.props.widgets, | ||
templates: this.props.templates, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To maintain backwards compatibility with current props, you could check for the old props here and use them if they were provided. Otherwise to be strict with Semver including this PR would mean releasing a V2. If we include backwards compatible props, then this could be released as V1.1. For example (this is pseudocode), this could provide backwards compatibility
@glasserc do you think that maintaining backwards compatibility with props is important? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that this would be in v2 (I've updated the first comment with this info) but yes we can change it to support backward compatibility. |
||
definitions: this.props.schema.definitions || {}, | ||
formContext: this.props.formContext || {}, | ||
}; | ||
|
@@ -190,7 +182,10 @@ export default class Form extends Component { | |
|
||
const { schema, uiSchema, formData, errorSchema, idSchema } = this.state; | ||
const registry = this.getRegistry(); | ||
const _SchemaField = registry.fields.SchemaField; | ||
const { | ||
fields: { SchemaField }, | ||
templates: { SubmitTemplate, ErrorListTemplate }, | ||
} = registry; | ||
|
||
return ( | ||
<form | ||
|
@@ -205,8 +200,8 @@ export default class Form extends Component { | |
acceptCharset={acceptcharset} | ||
noValidate={noHtml5Validate} | ||
onSubmit={this.onSubmit}> | ||
{this.renderErrors()} | ||
<_SchemaField | ||
{this.renderErrors(ErrorListTemplate)} | ||
<SchemaField | ||
schema={schema} | ||
uiSchema={uiSchema} | ||
errorSchema={errorSchema} | ||
|
@@ -219,15 +214,7 @@ export default class Form extends Component { | |
registry={registry} | ||
safeRenderCompletion={safeRenderCompletion} | ||
/> | ||
{children ? ( | ||
children | ||
) : ( | ||
<p> | ||
<button type="submit" className="btn btn-info"> | ||
Submit | ||
</button> | ||
</p> | ||
)} | ||
{children ? children : <SubmitTemplate />} | ||
</form> | ||
); | ||
} | ||
|
@@ -240,12 +227,11 @@ if (process.env.NODE_ENV !== "production") { | |
formData: PropTypes.any, | ||
widgets: PropTypes.objectOf( | ||
PropTypes.oneOfType([PropTypes.func, PropTypes.object]) | ||
), | ||
fields: PropTypes.objectOf(PropTypes.func), | ||
ArrayFieldTemplate: PropTypes.func, | ||
ObjectFieldTemplate: PropTypes.func, | ||
FieldTemplate: PropTypes.func, | ||
ErrorList: PropTypes.func, | ||
).isRequired, | ||
templates: PropTypes.objectOf( | ||
PropTypes.oneOfType([PropTypes.func, PropTypes.object]) | ||
).isRequired, | ||
fields: PropTypes.objectOf(PropTypes.func).isRequired, | ||
onChange: PropTypes.func, | ||
onError: PropTypes.func, | ||
showErrorList: PropTypes.bool, | ||
|
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.
What's this change about?