mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +01:00
Make email input be react controlled in loan and consign forms
This commit is contained in:
parent
e1477be393
commit
e442e6bcec
@ -4,11 +4,12 @@ import React from 'react';
|
|||||||
|
|
||||||
import Button from 'react-bootstrap/lib/Button';
|
import Button from 'react-bootstrap/lib/Button';
|
||||||
|
|
||||||
|
import InputTextAreaToggable from './input_textarea_toggable';
|
||||||
import Form from './form';
|
import Form from './form';
|
||||||
import Property from './property';
|
import Property from './property';
|
||||||
import InputTextAreaToggable from './input_textarea_toggable';
|
|
||||||
|
|
||||||
import AscribeSpinner from '../ascribe_spinner';
|
import AscribeSpinner from '../ascribe_spinner';
|
||||||
|
|
||||||
import AclInformation from '../ascribe_buttons/acl_information';
|
import AclInformation from '../ascribe_buttons/acl_information';
|
||||||
|
|
||||||
import { getLangText } from '../../utils/lang_utils.js';
|
import { getLangText } from '../../utils/lang_utils.js';
|
||||||
@ -30,12 +31,33 @@ let ConsignForm = React.createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
email: this.props.email
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getFormData() {
|
getFormData() {
|
||||||
return this.props.id;
|
return this.props.id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleEmailOnChange(event) {
|
||||||
|
// event.target.value is the submitted email of the consignee
|
||||||
|
this.setState({
|
||||||
|
email: event && event.target && event.target.value || ''
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { autoFocusProperty, email, id, handleSuccess, message, labels, url } = this.props;
|
const { email } = this.state;
|
||||||
|
const {
|
||||||
|
autoFocusProperty,
|
||||||
|
email: defaultEmail,
|
||||||
|
handleSuccess,
|
||||||
|
id,
|
||||||
|
message,
|
||||||
|
labels,
|
||||||
|
url } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
@ -64,12 +86,13 @@ let ConsignForm = React.createClass({
|
|||||||
autoFocus={autoFocusProperty === 'email'}
|
autoFocus={autoFocusProperty === 'email'}
|
||||||
name='consignee'
|
name='consignee'
|
||||||
label={labels.email || getLangText('Email')}
|
label={labels.email || getLangText('Email')}
|
||||||
editable={!email}
|
editable={!defaultEmail}
|
||||||
overrideForm={!!email}>
|
onChange={this.handleEmailOnChange}
|
||||||
|
overrideForm={!!defaultEmail}>
|
||||||
<input
|
<input
|
||||||
type="email"
|
type="email"
|
||||||
|
value={email}
|
||||||
placeholder={getLangText('Email of the consignee')}
|
placeholder={getLangText('Email of the consignee')}
|
||||||
defaultValue={email}
|
|
||||||
required/>
|
required/>
|
||||||
</Property>
|
</Property>
|
||||||
<Property
|
<Property
|
||||||
|
@ -89,6 +89,9 @@ let LoanForm = React.createClass({
|
|||||||
// fetch the available contractagreements (pending/accepted)
|
// fetch the available contractagreements (pending/accepted)
|
||||||
ContractAgreementListActions.fetchAvailableContractAgreementList(email, true);
|
ContractAgreementListActions.fetchAvailableContractAgreementList(email, true);
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
email: this.props.email || ''
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getFormData(){
|
getFormData(){
|
||||||
@ -98,13 +101,11 @@ let LoanForm = React.createClass({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleOnChange(event) {
|
handleEmailOnChange(event) {
|
||||||
// event.target.value is the submitted email of the loanee
|
// event.target.value is the submitted email of the loanee
|
||||||
if(event && event.target && event.target.value && event.target.value.match(/.*@.*\..*/)) {
|
this.setState({
|
||||||
this.getContractAgreementsOrCreatePublic(event.target.value);
|
email: event && event.target && event.target.value || ''
|
||||||
} else {
|
});
|
||||||
ContractAgreementListActions.flushContractAgreementList();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getContractAgreementId() {
|
getContractAgreementId() {
|
||||||
@ -218,9 +219,11 @@ let LoanForm = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { email } = this.state;
|
||||||
const {
|
const {
|
||||||
children,
|
children,
|
||||||
email,
|
email,
|
||||||
|
email: defaultEmail,
|
||||||
handleSuccess,
|
handleSuccess,
|
||||||
gallery,
|
gallery,
|
||||||
loanHeading,
|
loanHeading,
|
||||||
@ -255,9 +258,9 @@ let LoanForm = React.createClass({
|
|||||||
<Property
|
<Property
|
||||||
name='loanee'
|
name='loanee'
|
||||||
label={getLangText('Loanee Email')}
|
label={getLangText('Loanee Email')}
|
||||||
editable={!email}
|
editable={!defaultEmail}
|
||||||
onChange={this.handleOnChange}
|
onChange={this.handleEmailOnChange}
|
||||||
overrideForm={!!email}>
|
overrideForm={!!defaultEmail}>
|
||||||
<input
|
<input
|
||||||
value={email}
|
value={email}
|
||||||
type="email"
|
type="email"
|
||||||
|
Loading…
Reference in New Issue
Block a user