Skip to content

Commit

Permalink
Merge pull request #977 from ParthS007/button-disable
Browse files Browse the repository at this point in the history
Disable web buttons in forms after onClick
  • Loading branch information
amanda11 committed May 12, 2022
2 parents e4671a1 + 9978578 commit 62f5016
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ Changelog

in development
--------------
* Create a changelog and required machinery

Added
~~~~~

* Added feature for disabling button for synchronous responses
- Button gets disabled onClick on `Connect` and `Submit` in st2-login and st2-history module respectively

Contributed by @ParthS007
3 changes: 3 additions & 0 deletions apps/st2-history/history-popup.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class HistoryPopup extends React.Component {

state = {
preview: false,
disabled: false,
}

static getDerivedStateFromProps(props, state) {
Expand Down Expand Up @@ -89,6 +90,7 @@ export default class HistoryPopup extends React.Component {
delete this.state.payload[payLoadKey];
}
this.props.onSubmit(this.state.payload);
this.setState({ disabled: true });
}

render() {
Expand Down Expand Up @@ -136,6 +138,7 @@ export default class HistoryPopup extends React.Component {
submit
className="st2-details__toolbar-button"
value="Submit"
disabled={this.state.disabled}
onClick={(e) => this.handleSubmit(e)}
data-test="rerun_submit"
/>
Expand Down
6 changes: 4 additions & 2 deletions modules/st2-login/login.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export default class Login extends React.Component {
username: '',
password: '',
remember: true,
disabled: false,

server,
servers,
Expand All @@ -168,13 +169,13 @@ export default class Login extends React.Component {

connect(e) {
e.preventDefault();

this.setState({ disabled: true });
this.setState({ error: null });

const { server, username, password, remember } = this.state;
return api.connect(server, username, password, remember)
.then(() => this.props.onConnect())
.catch((err) => this.setState({ error: err.message }))
.catch((err) => this.setState({ error: err.message, disabled: false }))
;
}

Expand Down Expand Up @@ -240,6 +241,7 @@ export default class Login extends React.Component {
className={cx('st2-forms__button', style.button)}
type="submit"
value="Connect"
disabled={this.state.disabled}
/>

<label className={style.checkboxWrapper}>
Expand Down

0 comments on commit 62f5016

Please sign in to comment.