Skip to content

Commit e2cdce6

Browse files
authored
Fix rjsf-team#300: Properly reset a date widget value. (rjsf-team#303)
1 parent cbe878d commit e2cdce6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/components/widgets/DateWidget.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import BaseInput from "./BaseInput";
44

55

66
function DateWidget(props) {
7-
return <BaseInput type="date" {...props} />;
7+
const {onChange} = props;
8+
return (
9+
<BaseInput
10+
type="date"
11+
{...props}
12+
onChange={(value) => onChange(value || undefined)} />
13+
);
814
}
915

1016
if (process.env.NODE_ENV !== "production") {

test/StringField_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,20 @@ describe("StringField", () => {
331331

332332
expect(comp.state.errors).to.have.length.of(1);
333333
});
334+
335+
it("should properly reset field value when null is selected", () => {
336+
const {comp, node} = createFormComponent({schema: {
337+
type: "string",
338+
format: "date",
339+
}, uiSchema, liveValidate: true});
340+
341+
Simulate.change(node.querySelector("[type=date]"), {
342+
target: {value: null}
343+
});
344+
345+
expect(comp.state.formData).to.be.a("undefined");
346+
expect(comp.state.errors).to.have.length.of(0);
347+
});
334348
});
335349

336350
describe("AltDateTimeWidget", () => {

0 commit comments

Comments
 (0)