OSDN Git Service

submit the form when user hit enter
authorZhiting Lin <zlin035@uottawa.ca>
Mon, 21 May 2018 03:09:26 +0000 (11:09 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Mon, 21 May 2018 03:09:26 +0000 (11:09 +0800)
src/features/transactions/components/New/AdvancedTransactionForm.jsx
src/features/transactions/components/New/New.jsx
src/features/transactions/components/New/NormalTransactionForm.jsx

index 523010b..b55c399 100644 (file)
@@ -88,7 +88,8 @@ class AdvancedTxForm extends React.Component {
     }
 
     return (
-      <form onSubmit={handleSubmit(this.submitWithValidation)} {...disableAutocomplete}>
+      <form onSubmit={handleSubmit(this.submitWithValidation)} {...disableAutocomplete}
+            onKeyDown={(e) => { this.props.handleKeyDown(e, handleSubmit(this.submitWithValidation), this.disableSubmit(actions)) }}>
 
         <FormSection title='Actions'>
           {actions.map((action, index) =>
index 092fa7a..a12b409 100644 (file)
@@ -48,6 +48,13 @@ class Form extends React.Component {
     }
   }
 
+  handleKeyDown(e, cb, disable) {
+    if (e.key === 'Enter' && e.shiftKey === false && !disable) {
+      e.preventDefault()
+      cb()
+    }
+  }
+
   render() {
     const lang = this.props.lang
 
@@ -126,6 +133,7 @@ class Form extends React.Component {
               btmAmountUnit={this.props.btmAmountUnit}
               balanceAmount={balanceAmount}
               assetDecimal={assetDecimal}
+              handleKeyDown={this.handleKeyDown}
             /> }
 
             {this.state.showAdvanceTx &&
@@ -135,6 +143,7 @@ class Form extends React.Component {
               asset={this.props.asset}
               balanceAmount={balanceAmount}
               assetDecimal={assetDecimal}
+              handleKeyDown={this.handleKeyDown}
             />}
 
           </div>
index e971b5c..43d7dd5 100644 (file)
@@ -179,7 +179,9 @@ class NormalTxForm extends React.Component {
     const showBtmAmountUnit = (assetAlias.value === 'BTM' || assetId.value === btmID)
 
     return (
-        <form onSubmit={handleSubmit(this.submitWithValidation)} {...disableAutocomplete}>
+        <form
+          onSubmit={handleSubmit(this.submitWithValidation)} {...disableAutocomplete}
+          onKeyDown={(e) => { this.props.handleKeyDown(e, handleSubmit(this.submitWithValidation), this.disableSubmit(this.props.fields)) }}>
           <FormSection title={lang === 'zh' ? '简单交易' : 'Normal Trasaction'}>
             <label className={styles.title}>{lang === 'zh' ? '从' : 'From'}</label>
             <div className={styles.main}>