-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Added form readonly prop (#2553) #2554
Changes from all commits
d0119f6
3c72aaf
eab0da6
0ed2f2f
e84d505
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 |
---|---|---|
|
@@ -2226,6 +2226,33 @@ describeRepeated("Form common", createFormComponent => { | |
}); | ||
}); | ||
|
||
describe("Form readonly prop", () => { | ||
const schema = { | ||
type: "object", | ||
properties: { | ||
foo: { type: "string" }, | ||
bar: { type: "object", properties: { baz: { type: "string" } } }, | ||
}, | ||
}; | ||
const formData = { foo: "foo", bar: { baz: "baz" } }; | ||
|
||
it("should not have any readonly items", () => { | ||
const { node } = createFormComponent({ schema, formData }); | ||
|
||
expect(node.querySelectorAll("input:read-only")).to.have.length.of(0); | ||
}); | ||
|
||
it("should readonly all items", () => { | ||
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. Can we add a test just to ensure it works on nested objects / arrays? 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. Sure... I originally followed the pattern for the 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. Updated the one test to use a nested object 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. |
||
const { node } = createFormComponent({ | ||
schema, | ||
formData, | ||
readonly: true, | ||
}); | ||
|
||
expect(node.querySelectorAll("input:read-only")).to.have.length.of(2); | ||
}); | ||
}); | ||
|
||
describe("Attributes", () => { | ||
const formProps = { | ||
schema: {}, | ||
|
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.
Do you think it's better to call this "readOnly", for consistency with the readOnly react prop?
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.
Given that all the fields and widgets use
readonly
, I'd rather keep it consistent within the project. Perhaps we can deprecatereadonly
in favor ofreadOnly
in the future?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.
Ok, sounds good. I'd note that we did already deprecate
autocomplete
in favor ofautoComplete
(see https://github.com/rjsf-team/react-jsonschema-form/blob/master/docs/api-reference/form-props.md#autocomplete), but I guess we don't have an analogous situation there (becauseautoComplete
is not passed down as props to fields / widgets)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.
Done!