Skip to content
Open
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
22 changes: 22 additions & 0 deletions src/Card/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ class Card extends PureComponent {
formStatus: '',
}

this.forms = new Set()

this.bindElement = this.bindElement.bind(this)
this.handleSubmit = this.handleSubmit.bind(this)
this.handleCollapse = this.handleCollapse.bind(this)
this.setFormStatus = this.setFormStatus.bind(this)
this.addForm = this.addForm.bind(this)
this.delForm = this.delForm.bind(this)
}

getCollapsed() {
Expand All @@ -33,6 +37,14 @@ class Card extends PureComponent {
}

setFormStatus(status) {
if (this.forms.size > 1) {
if (this.state.formStatus !== 'overBound') {
this.setState({
formStatus: 'overBound',
})
}
return
}
if (status !== this.state.formStatus) {
this.setState({ formStatus: status })
}
Expand All @@ -56,6 +68,14 @@ class Card extends PureComponent {
else console.error(new Error('No form found.'))
}

addForm(id) {
this.forms.add(id)
}

delForm(id) {
this.forms.delete(id)
}

render() {
const { collapsible } = this.props
const collapsed = this.getCollapsed()
Expand All @@ -72,6 +92,8 @@ class Card extends PureComponent {
formStatus: this.state.formStatus,
onSubmit: this.handleSubmit,
setFormStatus: this.setFormStatus,
addForm: this.addForm,
delForm: this.delForm,
}

return (
Expand Down
14 changes: 14 additions & 0 deletions src/Card/Submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ class Submit extends PureComponent {
this.handleClick = this.handleClick.bind(this)
}

componentDidMount() {
this.check()
}

componentDidUpdate() {
this.check()
}

check() {
if (this.props.formStatus === 'overBound') {
console.error('Modal.Submit cannot be used when there are multiple Forms in Modal')
}
}

handleClick(e) {
e.persist()
setTimeout(() => {
Expand Down
7 changes: 6 additions & 1 deletion src/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Form extends Component {
}

componentDidMount() {
const { formRef } = this.props
const { formRef, addForm } = this.props
if (addForm) addForm(this.id)
if (formRef) {
if (typeof formRef === 'function') {
formRef(this.form)
Expand All @@ -69,6 +70,8 @@ class Form extends Component {

componentWillUnmount() {
this.props.datum.formUnmount = true
const { delForm } = this.props
if (delForm) delForm(this.id)
if (this.element) {
this.element.removeEventListener('submit', this.handleSubmit)
}
Expand Down Expand Up @@ -179,6 +182,8 @@ Form.propTypes = {
scrollToError: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
setFormStatus: PropTypes.func,
throttle: PropTypes.number,
delForm: PropTypes.func,
addForm: PropTypes.func,
}

Form.defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/Form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import useMode from './mode'
const exportForm = compose(
Datum.hoc({ type: 'form', bindProps: ['removeUndefined', 'error'] }),
formProvider
)(cardConsumer(Form, ['setFormStatus']))
)(cardConsumer(Form, ['setFormStatus', 'addForm', 'delForm']))
exportForm.Item = formConsumer(['formDatum', 'labelWidth', 'labelAlign', 'labelVerticalAlign', 'keepErrorHeight'])(Item)
exportForm.Field = inputable(Field)
exportForm.Block = formConsumer(['formDatum', 'combineRules'])(Block)
Expand Down