Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,23 @@ const uiSchema = {
};
```

Care should be taken when using the `required` property with arrays. An empty array is sufficient to pass that validation check. If you wish to ensure the user populates the array, you can specify the minimum number of items the user must select with the `minItems` property.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfect 👍

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent :)
I'll have to get to the tests over the weekend. It's a part of the code base I haven't been into yet.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there wasn't a text area widget section that I could see so I created one .... but it isn't right. I will have to look at it over the weekend.

What's checked in is passing, but it's not using the widget.

I've tried the change:

const uiSchema = {"ui:widget": "textarea"};

it("should handle an empty string change event", () => {
  const {comp, node} = createFormComponent({schema: {
    type: "string",
  }, uiSchema});

... which seems to me like it should work but that fails for reasons that currently escape me. I'll need to look at it over the weekend. Got to head off now though!


Example:

```js
const schema = {
type: "array",
minItems: 2,
title: "A multiple choices list",
items: {
type: "string",
enum: ["foo", "bar", "fuzz", "qux"],
},
uniqueItems: true
};
```

By default, checkboxes are stacked but if you prefer them inline:

```js
Expand Down
6 changes: 4 additions & 2 deletions src/components/widgets/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ function BaseInput(props) {
value,
readonly,
autofocus,
onChange,
options, // eslint-disable-line
schema, // eslint-disable-line
formContext, // eslint-disable-line
registry, // eslint-disable-line
...inputProps
} = props;
const _onChange = ({target: {value}}) => {
return props.onChange(value === "" ? undefined : value);
};
return (
<input
{...inputProps}
className="form-control"
readOnly={readonly}
autoFocus={autofocus}
value={typeof value === "undefined" ? "" : value}
onChange={(event) => onChange(event.target.value)}/>
onChange={_onChange} />
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/components/widgets/TextareaWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function TextareaWidget({
autofocus,
onChange
}) {
const _onChange = ({target: {value}}) => {
return onChange(value === "" ? undefined : value);
};
return (
<textarea
id={id}
Expand All @@ -22,7 +25,7 @@ function TextareaWidget({
disabled={disabled}
readOnly={readonly}
autoFocus={autofocus}
onChange={(event) => onChange(event.target.value)}/>
onChange={_onChange} />
);
}

Expand Down
26 changes: 26 additions & 0 deletions test/StringField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ describe("StringField", () => {
expect(comp.state.formData).eql("yo");
});

it("should handle an empty string change event", () => {
const {comp, node} = createFormComponent({schema: {
type: "string",
}});

Simulate.change(node.querySelector("input"), {
target: {value: ""}
});

expect(comp.state.formData).eql(undefined);
});

it("should fill field with data", () => {
const {node} = createFormComponent({schema: {
type: "string",
Expand Down Expand Up @@ -203,6 +215,20 @@ describe("StringField", () => {
});
});

describe("TextareaWidget", () => {
it("should handle an empty string change event", () => {
const {comp, node} = createFormComponent({schema: {
type: "string",
}});

Simulate.change(node.querySelector("input"), {
target: {value: ""}
});

expect(comp.state.formData).eql(undefined);
});
});

describe("DateTimeWidget", () => {
it("should render an datetime-local field", () => {
const {node} = createFormComponent({schema: {
Expand Down