Skip to content
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

Introduce Form autoComplete attribute and deprecate autocomplete #1483

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
2 changes: 1 addition & 1 deletion docs/form-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ The `Form` component supports the following html attributes:
method="post"
target="_blank"
action="/users/list"
autocomplete="off"
autoComplete="off"
enctype="multipart/form-data"
acceptcharset="ISO-8859-1" />
```
Expand Down
14 changes: 12 additions & 2 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ export default class Form extends Component {
method,
target,
action,
autocomplete,
autocomplete: deprecatedAutocomplete,
autoComplete: currentAutoComplete,
enctype,
acceptcharset,
noHtml5Validate,
Expand All @@ -328,6 +329,14 @@ export default class Form extends Component {
const registry = this.getRegistry();
const _SchemaField = registry.fields.SchemaField;
const FormTag = tagName ? tagName : "form";
if (deprecatedAutocomplete) {
console.warn(
"Using autocomplete property of Form is deprecated, use autoComplete instead."
);
}
const autoComplete = currentAutoComplete
? currentAutoComplete
: deprecatedAutocomplete;

return (
<FormTag
Expand All @@ -337,7 +346,7 @@ export default class Form extends Component {
method={method}
target={target}
action={action}
autoComplete={autocomplete}
autoComplete={autoComplete}
encType={enctype}
acceptCharset={acceptcharset}
noValidate={noHtml5Validate}
Expand Down Expand Up @@ -400,6 +409,7 @@ if (process.env.NODE_ENV !== "production") {
target: PropTypes.string,
action: PropTypes.string,
autocomplete: PropTypes.string,
autoComplete: PropTypes.string,
enctype: PropTypes.string,
acceptcharset: PropTypes.string,
noValidate: PropTypes.bool,
Expand Down
40 changes: 37 additions & 3 deletions test/Form_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ describeRepeated("Form common", createFormComponent => {
method: "post",
target: "_blank",
action: "/users/list",
autocomplete: "off",
autoComplete: "off",
enctype: "multipart/form-data",
acceptcharset: "ISO-8859-1",
noHtml5Validate: true,
Expand Down Expand Up @@ -2118,8 +2118,8 @@ describeRepeated("Form common", createFormComponent => {
expect(node.getAttribute("action")).eql(formProps.action);
});

it("should set attr autoComplete of form", () => {
expect(node.getAttribute("autocomplete")).eql(formProps.autocomplete);
it("should set attr autocomplete of form", () => {
expect(node.getAttribute("autocomplete")).eql(formProps.autoComplete);
});

it("should set attr enctype of form", () => {
Expand All @@ -2135,6 +2135,40 @@ describeRepeated("Form common", createFormComponent => {
});
});

describe("Deprecated autocomplete attribute", () => {
it("should set attr autocomplete of form", () => {
const formProps = {
schema: {},
autocomplete: "off",
};
const node = createFormComponent(formProps).node;
expect(node.getAttribute("autocomplete")).eql(formProps.autocomplete);
});

it("should log deprecation warning when it is used", () => {
sandbox.stub(console, "warn");
createFormComponent({
schema: {},
autocomplete: "off",
});
expect(
console.warn.calledWithMatch(
/Using autocomplete property of Form is deprecated/
)
).to.be.true;
});

it("should use autoComplete value if both autocomplete and autoComplete are used", () => {
const formProps = {
schema: {},
autocomplete: "off",
autoComplete: "on",
};
const node = createFormComponent(formProps).node;
expect(node.getAttribute("autocomplete")).eql(formProps.autoComplete);
});
});

describe("Custom format updates", () => {
it("Should update custom formats when customFormats is changed", () => {
const formProps = {
Expand Down