Skip to content

Commit 8bc093f

Browse files
committed
Do not enforce requirement for widget id prop.
1 parent 72d96bc commit 8bc093f

File tree

10 files changed

+29
-20
lines changed

10 files changed

+29
-20
lines changed

src/components/widgets/AltDateTimeWidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function AltDateTimeWidget(props) {
1010
if (process.env.NODE_ENV !== "production") {
1111
AltDateTimeWidget.propTypes = {
1212
schema: PropTypes.object.isRequired,
13-
id: PropTypes.string.isRequired,
13+
id: PropTypes.string,
1414
placeholder: PropTypes.string,
1515
value: React.PropTypes.string,
1616
required: PropTypes.bool,

src/components/widgets/AltDateWidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class AltDateWidget extends Component {
129129
if (process.env.NODE_ENV !== "production") {
130130
AltDateWidget.propTypes = {
131131
schema: PropTypes.object.isRequired,
132-
id: PropTypes.string.isRequired,
132+
id: PropTypes.string,
133133
placeholder: PropTypes.string,
134134
value: React.PropTypes.string,
135135
required: PropTypes.bool,

src/components/widgets/BaseInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ BaseInput.defaultProps = {
2222

2323
if (process.env.NODE_ENV !== "production") {
2424
BaseInput.propTypes = {
25-
id: PropTypes.string.isRequired,
25+
id: PropTypes.string,
2626
placeholder: PropTypes.string,
2727
value: PropTypes.any,
2828
required: PropTypes.bool,

src/components/widgets/CheckboxWidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function CheckboxWidget({
2929
if (process.env.NODE_ENV !== "production") {
3030
CheckboxWidget.propTypes = {
3131
schema: PropTypes.object.isRequired,
32-
id: PropTypes.string.isRequired,
32+
id: PropTypes.string,
3333
onChange: PropTypes.func,
3434
value: PropTypes.bool,
3535
required: PropTypes.bool,

src/components/widgets/HiddenWidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function HiddenWidget({id, value}) {
99

1010
if (process.env.NODE_ENV !== "production") {
1111
HiddenWidget.propTypes = {
12-
id: PropTypes.string.isRequired,
12+
id: PropTypes.string,
1313
value: PropTypes.oneOfType([
1414
React.PropTypes.string,
1515
React.PropTypes.number,

src/components/widgets/RadioWidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function RadioWidget({
3838
if (process.env.NODE_ENV !== "production") {
3939
RadioWidget.propTypes = {
4040
schema: PropTypes.object.isRequired,
41-
id: PropTypes.string.isRequired,
41+
id: PropTypes.string,
4242
options: PropTypes.array.isRequired,
4343
placeholder: PropTypes.string,
4444
value: PropTypes.any,

src/components/widgets/SelectWidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function SelectWidget({
5959
if (process.env.NODE_ENV !== "production") {
6060
SelectWidget.propTypes = {
6161
schema: PropTypes.object.isRequired,
62-
id: PropTypes.string.isRequired,
62+
id: PropTypes.string,
6363
options: PropTypes.array.isRequired,
6464
placeholder: PropTypes.string,
6565
value: PropTypes.any,

src/components/widgets/TextareaWidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function TextWidget({
2727
if (process.env.NODE_ENV !== "production") {
2828
TextWidget.propTypes = {
2929
schema: PropTypes.object.isRequired,
30-
id: PropTypes.string.isRequired,
30+
id: PropTypes.string,
3131
placeholder: PropTypes.string,
3232
value: PropTypes.string,
3333
required: PropTypes.bool,

src/validate.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function toErrorSchema(errors) {
5353
if (Array.isArray(parent.__errors)) {
5454
// We store the list of errors for this node in a property named __errors
5555
// to avoid name collision with a possible sub schema field named
56-
// "errors" (see `validate.createErrorHandler`).
56+
// "errors" (see `createErrorHandler`).
5757
parent.__errors = parent.__errors.concat(message);
5858
} else {
5959
parent.__errors = [message];
@@ -62,7 +62,7 @@ function toErrorSchema(errors) {
6262
}, {});
6363
}
6464

65-
export function toErrorList(errorSchema) {
65+
function toErrorList(errorSchema) {
6666
return Object.keys(errorSchema).reduce((acc, key) => {
6767
const field = errorSchema[key];
6868
if ("__errors" in field) {
@@ -79,7 +79,7 @@ function createErrorHandler(formData) {
7979
const handler = {
8080
// We store the list of errors for this node in a property named __errors
8181
// to avoid name collision with a possible sub schema field named
82-
// "errors" (see `utils.toErrorSchema`).
82+
// "errors" (see `toErrorSchema`).
8383
__errors: [],
8484
addError(message) {
8585
this.__errors.push(message);
@@ -105,9 +105,18 @@ function unwrapErrorHandler(errorHandler) {
105105
}
106106

107107
/**
108-
* This function processes the formData with a user `validate` contributed
109-
* function, which receives the form data and an `errorHandler` object that
110-
* will be used to add custom validation errors for each field.
108+
* This function processes the formData against:
109+
*
110+
* 1. A JSON schema object, then
111+
* 2. An optional `validate` contributed function, which receives the form data
112+
* and an `errorHandler` object used to add custom validation errors for each
113+
* field.
114+
*
115+
* It returns a Promise resolving with an object exposing the following
116+
* properties:
117+
*
118+
* - `errors`: The list of encountered validation errors;
119+
* - `errorSchema`: An error tree matching the formData structure.
111120
*
112121
* @return {Promise}
113122
*/
@@ -121,8 +130,8 @@ export default function validateFormData(formData, schema, customValidate) {
121130

122131
const errorHandler = createErrorHandler(formData);
123132
return Promise.resolve(customValidate(formData, errorHandler))
124-
.then(UserErrorHandler => {
125-
const userErrorSchema = unwrapErrorHandler(UserErrorHandler);
133+
.then(userErrorHandler => {
134+
const userErrorSchema = unwrapErrorHandler(userErrorHandler);
126135
const newErrorSchema = mergeObjects(errorSchema, userErrorSchema, true);
127136
// XXX: The errors list produced is not fully compliant with the format
128137
// exposed by the jsonschema lib, which contains full field paths and other

test/validate_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("Validation", () => {
1818

1919
let errors, errorSchema;
2020

21-
beforeEach(() => {
21+
beforeEach(function* () {
2222
return validateFormData({foo: 42}, schema)
2323
.then(result => {
2424
errors = result.errors;
@@ -49,7 +49,7 @@ describe("Validation", () => {
4949
}
5050
};
5151

52-
beforeEach(() => {
52+
beforeEach(function* () {
5353
const validate = (formData, errors) => {
5454
if (formData.pass1 !== formData.pass2) {
5555
errors.pass2.addError("passwords don't match.");
@@ -119,7 +119,7 @@ describe("Validation", () => {
119119

120120
var comp, node, onError;
121121

122-
beforeEach(() => {
122+
beforeEach(function* () {
123123
onError = sandbox.spy();
124124
const compInfo = createFormComponent({schema, formData: {
125125
foo: undefined
@@ -165,7 +165,7 @@ describe("Validation", () => {
165165

166166
var comp, node, onError;
167167

168-
beforeEach(() => {
168+
beforeEach(function* () {
169169
onError = sandbox.spy();
170170
const compInfo = createFormComponent({schema, formData: {
171171
foo: "123456789"

0 commit comments

Comments
 (0)