1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

add reset functionality for InputDate and LoanForm

This commit is contained in:
Tim Daubenschütz 2015-09-10 13:24:32 +02:00
parent 9297f804fe
commit 5588f766c1
4 changed files with 37 additions and 21 deletions

View File

@ -41,7 +41,9 @@ let Form = React.createClass({
// It will make use of the GlobalNotification
isInline: React.PropTypes.bool,
autoComplete: React.PropTypes.string
autoComplete: React.PropTypes.string,
onReset: React.PropTypes.func
},
getDefaultProps() {
@ -61,6 +63,12 @@ let Form = React.createClass({
},
reset() {
// If onReset prop is defined from outside,
// notify component that a form reset is happening.
if(this.props.onReset && typeof this.props.onReset === 'function') {
this.props.onReset();
}
for(let ref in this.refs) {
if (typeof this.refs[ref].reset === 'function'){
this.refs[ref].reset();
@ -184,8 +192,16 @@ let Form = React.createClass({
buttons = (
<div className="row" style={{margin: 0}}>
<p className="pull-right">
<Button className="btn btn-default btn-sm ascribe-margin-1px" type="submit">{this.props.buttonSubmitText}</Button>
<Button className="btn btn-danger btn-delete btn-sm ascribe-margin-1px" onClick={this.reset}>CANCEL</Button>
<Button
className="btn btn-default btn-sm ascribe-margin-1px"
type="submit">
{this.props.buttonSubmitText}
</Button>
<Button
className="btn btn-danger btn-delete btn-sm ascribe-margin-1px"
type="reset">
CANCEL
</Button>
</p>
</div>
);

View File

@ -69,10 +69,11 @@ let LoanForm = React.createClass({
},
handleOnChange(event) {
let potentialEmail = event.target.value;
if(potentialEmail.match(/.*@.*/)) {
LoanContractActions.fetchLoanContract(potentialEmail);
// event.target.value is the submitted email of the loanee
if(event && event.target && event.target.value && event.target.value.match(/.*@.*/)) {
LoanContractActions.fetchLoanContract(event.target.value);
} else {
LoanContractActions.flushLoanContract();
}
},
@ -143,6 +144,7 @@ let LoanForm = React.createClass({
ref='form'
url={this.props.url}
getFormData={this.getFormData}
onReset={this.handleOnChange}
handleSuccess={this.props.handleSuccess}
buttons={this.getButtons()}
spinner={

View File

@ -80,19 +80,12 @@ let RegisterPieceForm = React.createClass({
url={ApiUrls.pieces_list}
handleSuccess={this.props.handleSuccess}
buttons={
<span>
<button
type="submit"
className="btn ascribe-btn ascribe-btn-login"
disabled={!this.state.isUploadReady || this.props.disabled}>
{this.props.submitMessage}
</button>
<button
type="reset"
className="btn ascribe-btn ascribe-btn-login">
Reset
</button>
</span>
<button
type="submit"
className="btn ascribe-btn ascribe-btn-login"
disabled={!this.state.isUploadReady || this.props.disabled}>
{this.props.submitMessage}
</button>
}
spinner={
<span className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">

View File

@ -18,7 +18,8 @@ let InputDate = React.createClass({
getInitialState() {
return {
value: null
value: null,
value_moment: null
};
},
@ -45,6 +46,10 @@ let InputDate = React.createClass({
});
},
reset() {
this.setState(this.getInitialState());
},
render() {
return (
<div>