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

Fixes #5959 - jquery-bootstrap example uses handleHidden which does not exist #5961

Merged
merged 1 commit into from
Feb 2, 2016
Merged
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
15 changes: 14 additions & 1 deletion examples/jquery-bootstrap/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ var BootstrapModal = React.createClass({
componentDidMount: function() {
// When the component is added, turn it into a modal
$(this.refs.root).modal({backdrop: 'static', keyboard: false, show: false});

// Bootstrap's modal class exposes a few events for hooking into modal
// functionality. Lets hook into one of them:
$(this.refs.root).on('hidden.bs.modal', this.handleHidden);
},
componentWillUnmount: function() {
$(this.refs.root).off('hidden', this.handleHidden);
$(this.refs.root).off('hidden.bs.modal', this.handleHidden);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with this code, why did this line change? That is to say: what is the difference between hidden and hidden.bs.modal, and how do we know which one is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hidden wasn't working for me. I checked the Bootstrap docs which shows to use hidden.bs.model and that did work for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it may not have been working because there was no listener in place for either event ie.

$(this.refs.root).on('hidden.bs.modal', this.handleHidden);
// or
$(this.refs.root).on('hidden', this.handleHidden);

I added that listener on line 25

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, both event names work. The syntax is how jQuery namespaces events. So it wasn't working for me initially because there wasn't an event listener setup when the component was mounted.

},
close: function() {
$(this.refs.root).modal('hide');
Expand Down Expand Up @@ -84,6 +88,11 @@ var BootstrapModal = React.createClass({
if (this.props.onConfirm) {
this.props.onConfirm();
}
},
handleHidden: function() {
if (this.props.onHidden) {
this.props.onHidden();
}
}
});

Expand All @@ -102,6 +111,7 @@ var Example = React.createClass({
cancel="Cancel"
onCancel={this.handleCancel}
onConfirm={this.closeModal}
onHidden={this.handleModalDidClose}
title="Hello, Bootstrap!">
This is a React component powered by jQuery and Bootstrap!
</BootstrapModal>
Expand All @@ -120,6 +130,9 @@ var Example = React.createClass({
},
closeModal: function() {
this.refs.modal.close();
},
handleModalDidClose: function() {
alert("The modal has been dismissed!");
}
});

Expand Down