From 5588f766c1a82f4e761dd59dfde3828eb7dccce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 10 Sep 2015 13:24:32 +0200 Subject: [PATCH] add reset functionality for InputDate and LoanForm --- js/components/ascribe_forms/form.js | 22 ++++++++++++++++--- js/components/ascribe_forms/form_loan.js | 10 +++++---- .../ascribe_forms/form_register_piece.js | 19 +++++----------- js/components/ascribe_forms/input_date.js | 7 +++++- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/js/components/ascribe_forms/form.js b/js/components/ascribe_forms/form.js index 182e7ba7..115a8d8e 100644 --- a/js/components/ascribe_forms/form.js +++ b/js/components/ascribe_forms/form.js @@ -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 = (

- - + +

); diff --git a/js/components/ascribe_forms/form_loan.js b/js/components/ascribe_forms/form_loan.js index 276ff492..60dad486 100644 --- a/js/components/ascribe_forms/form_loan.js +++ b/js/components/ascribe_forms/form_loan.js @@ -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={ diff --git a/js/components/ascribe_forms/form_register_piece.js b/js/components/ascribe_forms/form_register_piece.js index e9b3df57..8f2666c0 100644 --- a/js/components/ascribe_forms/form_register_piece.js +++ b/js/components/ascribe_forms/form_register_piece.js @@ -80,19 +80,12 @@ let RegisterPieceForm = React.createClass({ url={ApiUrls.pieces_list} handleSuccess={this.props.handleSuccess} buttons={ - - - - + } spinner={ diff --git a/js/components/ascribe_forms/input_date.js b/js/components/ascribe_forms/input_date.js index 837221e5..3e2892c0 100644 --- a/js/components/ascribe_forms/input_date.js +++ b/js/components/ascribe_forms/input_date.js @@ -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 (