OSDN Git Service

fix id/alias exchange bug
authorYongfeng LI <wliyongfeng@gmail.com>
Sun, 11 Feb 2018 07:42:54 +0000 (15:42 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Sun, 11 Feb 2018 07:42:54 +0000 (15:42 +0800)
src/features/shared/components/ObjectSelectorField/ObjectSelectorField.jsx
src/features/transactions/components/New/New.jsx

index 97f6916..424a9d1 100644 (file)
@@ -34,6 +34,19 @@ class ObjectSelectorField extends React.Component {
   }
 
   render() {
+    const idOnChange = (event) => {
+      this.props.fieldProps.id.onChange(event.target.value)
+      this.props.fieldProps.alias.onChange('')
+    }
+
+    const aliasOnChange = value => {
+      this.props.fieldProps.alias.onChange(value)
+      this.props.fieldProps.id.onChange('')
+    }
+
+    const idProps = Object.assign({...this.props.fieldProps.id}, {onChange: idOnChange})
+    const aliasProps = Object.assign({...this.props.fieldProps.alias}, {onChange: aliasOnChange})
+
     return(
       <div className='form-group'>
         {this.props.title && <FieldLabel>{this.props.title}</FieldLabel>}
@@ -54,13 +67,13 @@ class ObjectSelectorField extends React.Component {
             <input className='form-control'
               type={this.state.type}
               placeholder={`${this.props.title} ID`}
-              {...this.props.fieldProps.id} />}
+              {...idProps} />}
 
           {this.state.selected == ALIAS_SELECTED &&
             <this.props.aliasField
               className={styles.aliasFieldGroupItem}
               placeholder={`Start typing ${this.props.title.toLowerCase()} alias...`}
-              fieldProps={this.props.fieldProps.alias} />}
+              fieldProps={aliasProps} />}
 
         </div>
         {this.props.hint && <span className='help-block'>{this.props.hint}</span>}
index 996a56e..da74ced 100644 (file)
@@ -25,7 +25,8 @@ class Form extends React.Component {
   constructor(props) {
     super(props)
     this.state = {
-      showDropdown: false
+      showDropdown: false,
+      showAdvanced: false
     }
 
     this.submitWithValidation = this.submitWithValidation.bind(this)
@@ -82,13 +83,17 @@ class Form extends React.Component {
   }
 
   disableSubmit(actions, normalTransaction) {
-    // let isNormalShow = true
-    // for (let key in normalTransaction){
-    //   isNormalShow = isNormalShow & normalTransaction[key].dirty
-    // }
-    // return !isNormalShow & actions.length == 0 & !this.state.showAdvanced
-    // return  actions.length == 0 & !this.state.showAdvanced
-    return  false
+    if (this.showAdvance) {
+      return actions.length == 0 & !this.state.showAdvanced
+    }
+
+    const hasValue = target => {
+      return !!(target && target.value)
+    }
+
+    return !((hasValue(normalTransaction.accountId) || hasValue(normalTransaction.accountAlias)) &&
+      (hasValue(normalTransaction.assetId)|| hasValue(normalTransaction.assetAlias)) &&
+      hasValue(normalTransaction.address) && (hasValue(normalTransaction.amount)))
   }
 
   removeActionItem(index) {