1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 10:25:08 +01:00

Fix references to form due to nested property elements

This commit is contained in:
Brett Sun 2015-12-03 17:19:17 +01:00
parent 9c64cf2b80
commit f5a527b251
4 changed files with 57 additions and 27 deletions

View File

@ -124,8 +124,12 @@ let Form = React.createClass({
getFormData() { getFormData() {
let data = {}; let data = {};
for (let ref in this.refs) { for (let refName in this.refs) {
data[this.refs[ref].props.name] = this.refs[ref].state.value; const ref = this.refs[refName];
if (ref.state && 'value' in ref.state) {
data[ref.props.name] = ref.state.value;
}
} }
if (typeof this.props.getFormData === 'function') { if (typeof this.props.getFormData === 'function') {

View File

@ -57,13 +57,6 @@ let LoanForm = React.createClass({
}; };
}, },
getFormData() {
return mergeOptions(
this.props.id,
this.refs.contractAgreement.getFormDataForProperty()
);
},
handleEmailOnChange(event) { handleEmailOnChange(event) {
// event.target.value is the submitted email of the loanee // event.target.value is the submitted email of the loanee
this.setState({ this.setState({
@ -75,6 +68,13 @@ let LoanForm = React.createClass({
this.handleEmailOnChange(); this.handleEmailOnChange();
}, },
getFormData() {
return mergeOptions(
this.props.id,
this.refs.contractAgreement.getFormDataForProperty()
);
},
getButtons() { getButtons() {
if(this.props.loanHeading) { if(this.props.loanHeading) {
return ( return (
@ -191,10 +191,11 @@ let LoanForm = React.createClass({
required={showPersonalMessage}/> required={showPersonalMessage}/>
</Property> </Property>
<ContractAgreementProperty <ContractAgreementProperty
ref='contractAgreement' ref={ref => this.refs.contractAgreement = ref}
createPublicContractAgreement={createPublicContractAgreement} createPublicContractAgreement={createPublicContractAgreement}
email={email} email={email}
embedClassName={'loan-form'} embedClassName={'loan-form'}
name='contract_agreement'
label={getLangText('Loan Contract')} /> label={getLangText('Loan Contract')} />
<Property <Property
name='password' name='password'

View File

@ -13,10 +13,16 @@ import { isEmail } from '../../utils/regex_utils';
let ContractAgreementProperty = React.createClass({ let ContractAgreementProperty = React.createClass({
propTypes: { propTypes: {
createPublicContractAgreement: React.PropTypes.string, createPublicContractAgreement: React.PropTypes.bool,
email: React.PropTypes.string, email: React.PropTypes.string,
embedClassName: React.PropTypes.string, embedClassName: React.PropTypes.string,
label: React.PropTypes.string label: React.PropTypes.string,
// Necessary for Form to pick this element up as a ref
name: React.PropTypes.string,
// Passed down from Form element
handleChange: React.PropTypes.func
}, },
getDefaultProps() { getDefaultProps() {
@ -37,11 +43,13 @@ let ContractAgreementProperty = React.createClass({
componentWillReceiveProps({ email: nextEmail }) { componentWillReceiveProps({ email: nextEmail }) {
const { contractAgreementList } = this.state; const { contractAgreementList } = this.state;
if (nextEmail && this.props.email !== nextEmail && isEmail(nextEmail)) { if (this.props.email !== nextEmail) {
if (isEmail(nextEmail)) {
this.getContractAgreementsOrCreatePublic(nextEmail); this.getContractAgreementsOrCreatePublic(nextEmail);
} else if (contractAgreementList && contractAgreementList.length > 0) { } else if (contractAgreementList && contractAgreementList.length > 0) {
ContractAgreementListActions.flushContractAgreementList(); ContractAgreementListActions.flushContractAgreementList();
} }
}
}, },
componentWillUnmount() { componentWillUnmount() {
@ -53,14 +61,21 @@ let ContractAgreementProperty = React.createClass({
}, },
getFormDataForProperty() { getFormDataForProperty() {
return this.getContractAgreementId(); const contractAgreementId = this.getContractAgreementId();
const formData = {
'terms': this.refs.terms.state.value
};
if (contractAgreementId) {
formData.contract_agreement_id = contractAgreementId;
}
return formData;
}, },
getContractAgreementId() { getContractAgreementId() {
if (this.state.contractAgreementList && this.state.contractAgreementList.length > 0) { if (this.state.contractAgreementList && this.state.contractAgreementList.length > 0) {
return { 'contract_agreement_id': this.state.contractAgreementList[0].id }; return this.state.contractAgreementList[0].id;
} else {
return {};
} }
}, },
@ -82,7 +97,8 @@ let ContractAgreementProperty = React.createClass({
return ( return (
<Property <Property
name='appendix' name='appendix'
label={getLangText('Appendix')}> label={getLangText('Appendix')}
handleChange={this.props.handleChange}>
<pre className="ascribe-pre">{appendix.default}</pre> <pre className="ascribe-pre">{appendix.default}</pre>
</Property> </Property>
); );
@ -91,24 +107,27 @@ let ContractAgreementProperty = React.createClass({
}, },
getContractCheckbox() { getContractCheckbox() {
const { embedClassName, handleChange, label } = this.props;
const { contractAgreementList } = this.state; const { contractAgreementList } = this.state;
if (contractAgreementList && contractAgreementList.length > 0) { if (contractAgreementList && contractAgreementList.length > 0) {
// we need to define a key on the InputCheckboxes as otherwise
// react is not rerendering them on a store switch and is keeping
// the default value of the component (which is in that case true)
const contractAgreement = contractAgreementList[0]; const contractAgreement = contractAgreementList[0];
const { issuer: contractIssuer, blob: { url_safe: contractUrl } } = contractAgreement.contract; const { issuer: contractIssuer, blob: { url_safe: contractUrl } } = contractAgreement.contract;
// we need to define a key on the InputCheckboxes as otherwise
// react is not rerendering them on a store switch and is keeping
// the default value of the component (which is in that case true)
if (contractAgreement.datetime_accepted) { if (contractAgreement.datetime_accepted) {
return ( return (
<Property <Property
ref="terms"
name="terms" name="terms"
label={this.props.label} label={label}
hidden={false} hidden={false}
handleChange={handleChange}
className="notification-contract-pdf"> className="notification-contract-pdf">
<embed <embed
className={this.props.embedClassName} className={embedClassName}
src={contractUrl} src={contractUrl}
alt="pdf" alt="pdf"
pluginspage="http://www.adobe.com/products/acrobat/readstep2.html"/> pluginspage="http://www.adobe.com/products/acrobat/readstep2.html"/>
@ -125,8 +144,10 @@ let ContractAgreementProperty = React.createClass({
} else { } else {
return ( return (
<Property <Property
ref="terms"
name="terms" name="terms"
className="ascribe-property-collapsible-toggle" className="ascribe-property-collapsible-toggle"
handleChange={handleChange}
style={{paddingBottom: 0}}> style={{paddingBottom: 0}}>
<InputCheckbox <InputCheckbox
key="terms_explicitly" key="terms_explicitly"
@ -144,7 +165,9 @@ let ContractAgreementProperty = React.createClass({
} else { } else {
return ( return (
<Property <Property
ref="terms"
name="terms" name="terms"
handleChange={handleChange}
style={{paddingBottom: 0}} style={{paddingBottom: 0}}
hidden={true}> hidden={true}>
<InputCheckbox <InputCheckbox

View File

@ -31,12 +31,14 @@
margin-top: .5em; margin-top: .5em;
margin-bottom: 1em; margin-bottom: 1em;
.consign-form,
.loan-form { .loan-form {
margin-top: .5em; margin-top: .5em;
height: 45vh; height: 45vh;
} }
} }
.consign-form,
.loan-form { .loan-form {
height: 40vh; height: 40vh;
} }