Skip to content

Commit

Permalink
Merge pull request #3896 from Sam-Apostel/master
Browse files Browse the repository at this point in the history
Add prop `form` -  input form attribute
  • Loading branch information
martijnrusschen committed Jan 26, 2023
2 parents fe19799 + fdde92f commit be27eb2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs-site/src/components/Examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import CloseOnScrollCallback from "../../examples/closeOnScrollCallback";
import SelectsRange from "../../examples/selectsRange";
import selectsRangeWithDisabledDates from "../../examples/selectsRangeWithDisabledDates";
import CalendarStartDay from "../../examples/calendarStartDay";
import ExternalForm from "../../examples/externalForm";

import "./style.scss";
import "react-datepicker/dist/react-datepicker.css";
Expand Down Expand Up @@ -456,6 +457,10 @@ export default class exampleComponents extends React.Component {
title: "Calendar Start day",
component: CalendarStartDay,
},
{
title: "External Form",
component: ExternalForm,
},
];

handleAnchorClick = (e, id) => {
Expand Down
17 changes: 17 additions & 0 deletions docs-site/src/examples/externalForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
() => {
const [startDate, setStartDate] = useState(null);

return (
<>
<DatePicker
selected={startDate}
onChange={(date) => setStartDate(date)}
required
form="external-form"
/>
<form id="external-form">
<input type="submit" />
</form>
</>
);
};
2 changes: 2 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default class DatePicker extends React.Component {
),
filterDate: PropTypes.func,
fixedHeight: PropTypes.bool,
form: PropTypes.string,
formatWeekNumber: PropTypes.func,
highlightDates: PropTypes.array,
id: PropTypes.string,
Expand Down Expand Up @@ -1046,6 +1047,7 @@ export default class DatePicker extends React.Component {
onKeyDown: this.onInputKeyDown,
id: this.props.id,
name: this.props.name,
form: this.props.form,
autoFocus: this.props.autoFocus,
placeholder: this.props.placeholderText,
disabled: this.props.disabled,
Expand Down

0 comments on commit be27eb2

Please sign in to comment.