|
|
@ -26,20 +26,45 @@ class TxForm extends React.Component { |
|
|
|
this.refs.txForm.reset(); |
|
|
|
this.refs.txForm.reset(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleChange(evt) { |
|
|
|
|
|
|
|
var currTx = this.state.tx; |
|
|
|
|
|
|
|
console.log(evt.target.name); |
|
|
|
|
|
|
|
console.log(evt.target.value); |
|
|
|
|
|
|
|
currTx[evt.target.name] = evt.target.value; |
|
|
|
|
|
|
|
console.log(currTx); |
|
|
|
|
|
|
|
this.setState({updated: currTx}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
render() { |
|
|
|
|
|
|
|
this.state = this.state || {}; |
|
|
|
|
|
|
|
if (this.state.updated) { |
|
|
|
|
|
|
|
this.state.tx = this.state.updated; |
|
|
|
|
|
|
|
delete this.state["updated"]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.state.tx = this.props.tx; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (Object.keys(this.state.tx).length == 0) { |
|
|
|
|
|
|
|
this.state.tx = { |
|
|
|
|
|
|
|
id: '', amount: '', currency: '', |
|
|
|
|
|
|
|
date: '2015-12-16', note: '' |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<form className="tx-edit" ref="txForm" onSubmit={this.updateTx}> |
|
|
|
<form className="tx-edit" ref="txForm" onSubmit={this.updateTx}> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="small-6 medium-8 grid-content"> |
|
|
|
<div className="small-6 medium-8 grid-content"> |
|
|
|
<input type="text" ref="amount" placeholder="Amount" required /> |
|
|
|
<input type="text" ref="amount" placeholder="Amount" required |
|
|
|
|
|
|
|
name="amount" value={this.state.tx.amount} onChange={this.handleChange} /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="small-6 medium-4 grid-content"> |
|
|
|
<div className="small-6 medium-4 grid-content"> |
|
|
|
<input type="text" ref="currency" placeholder="Currency" required /> |
|
|
|
<input type="text" ref="currency" placeholder="Currency" required |
|
|
|
|
|
|
|
name="currency" value={this.state.tx.currency} onChange={this.handleChange} /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="small-12 medium-6 grid-content"> |
|
|
|
<div className="small-12 medium-6 grid-content"> |
|
|
|
<input type="text" ref="date" placeholder="Date" required /> |
|
|
|
<input type="text" ref="date" placeholder="Date" required |
|
|
|
|
|
|
|
name="date" value={this.state.tx.date} onChange={this.handleChange} /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="small-12 medium-6 grid-content"> |
|
|
|
<div className="small-12 medium-6 grid-content"> |
|
|
|
<select ref="account"> |
|
|
|
<select ref="account"> |
|
|
@ -54,12 +79,13 @@ class TxForm extends React.Component { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="small-12 medium-12 grid-content"> |
|
|
|
<div className="small-12 medium-12 grid-content"> |
|
|
|
<textarea type="text" ref="note" placeholder="Note"></textarea> |
|
|
|
<textarea type="text" ref="note" placeholder="Note" name="note"
|
|
|
|
|
|
|
|
value={this.state.tx.note} onChange={this.handleChange}></textarea> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="small-12 medium-12 grid-content"> |
|
|
|
<div className="small-12 medium-12 grid-content"> |
|
|
|
<input type="hidden" ref="id" value="" /> |
|
|
|
<input type="hidden" ref="id" value={this.state.tx.id} /> |
|
|
|
<button type="submit" className="success button">+ Add Tx</button> |
|
|
|
<button type="submit" className="success button">+ Add Tx</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -70,7 +96,8 @@ class TxForm extends React.Component { |
|
|
|
|
|
|
|
|
|
|
|
TxForm.propTypes = { |
|
|
|
TxForm.propTypes = { |
|
|
|
txFormHandler : React.PropTypes.func.isRequired, |
|
|
|
txFormHandler : React.PropTypes.func.isRequired, |
|
|
|
accounts : React.PropTypes.array.isRequired |
|
|
|
accounts : React.PropTypes.array.isRequired, |
|
|
|
|
|
|
|
tx : React.PropTypes.object, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default TxForm; |
|
|
|
export default TxForm; |
|
|
|