sipp11
9 years ago
5 changed files with 87 additions and 10 deletions
@ -0,0 +1,57 @@
|
||||
/* |
||||
Add Tx Form |
||||
<AddTxForm /> |
||||
*/ |
||||
|
||||
import React from 'react'; |
||||
import AccountStore from '../stores/AccountStore'; |
||||
|
||||
class TxForm extends React.Component { |
||||
|
||||
constructor(props) { |
||||
super(props); |
||||
console.log(AccountStore.accounts) |
||||
this.state = {accounts: []}; |
||||
} |
||||
|
||||
updateTx(event) { |
||||
// 1. Stop the form from submitting
|
||||
event.preventDefault(); |
||||
// 2. Take the data from the form and create an object
|
||||
var tx = { |
||||
id : this.refs.id.value, |
||||
price : this.refs.price.value, |
||||
status : this.refs.status.value, |
||||
desc : this.refs.desc.value, |
||||
image : this.refs.image.value |
||||
} |
||||
|
||||
// 3. Add the fish to the App State
|
||||
this.props.addFish(fish); |
||||
this.refs.fishForm.reset(); |
||||
} |
||||
|
||||
render() { |
||||
return ( |
||||
<form className="tx-edit" ref="txForm" onSubmit={this.updateTx}> |
||||
<input type="hidden" ref="id" value="" /> |
||||
<input type="text" ref="amount" placeholder="Amount" /> |
||||
<input type="text" ref="currency" placeholder="Currency" /> |
||||
<input type="text" ref="date" placeholder="Date" /> |
||||
<select ref="account"> |
||||
{this.state.accounts.map((account) => { |
||||
return ( |
||||
<option value="{account.id}"> |
||||
{account.title} ({account.currency})</option> |
||||
) |
||||
})} |
||||
</select> |
||||
<textarea type="text" ref="note" placeholder="Note"></textarea> |
||||
<input type="text" ref="image" placeholder="URL to Image" /> |
||||
<button type="submit">+ Add Tx </button> |
||||
</form> |
||||
) |
||||
} |
||||
}; |
||||
|
||||
export default TxForm; |
Loading…
Reference in new issue