浏览代码

validate form

itizawa 6 年之前
父节点
当前提交
bae22b65e5
共有 1 个文件被更改,包括 9 次插入2 次删除
  1. 9 2
      src/client/js/components/Admin/Notification/UserTriggerNotification.jsx

+ 9 - 2
src/client/js/components/Admin/Notification/UserTriggerNotification.jsx

@@ -24,7 +24,9 @@ class UserTriggerNotification extends React.Component {
 
 
     this.changePathPattern = this.changePathPattern.bind(this);
     this.changePathPattern = this.changePathPattern.bind(this);
     this.changeChannel = this.changeChannel.bind(this);
     this.changeChannel = this.changeChannel.bind(this);
+    this.validateForm = this.validateForm.bind(this);
     this.onClickSubmit = this.onClickSubmit.bind(this);
     this.onClickSubmit = this.onClickSubmit.bind(this);
+
   }
   }
 
 
   /**
   /**
@@ -41,12 +43,17 @@ class UserTriggerNotification extends React.Component {
     this.setState({ channel });
     this.setState({ channel });
   }
   }
 
 
+  validateForm() {
+    return this.state.pathPattern !== '' && this.state.channel;
+  }
+
   async onClickSubmit() {
   async onClickSubmit() {
-    const { t, adminNotificationContainer } = this.props;
+    const { t } = this.props;
 
 
     try {
     try {
       // await adminNotificationContainer.updateSlackAppConfiguration();
       // await adminNotificationContainer.updateSlackAppConfiguration();
       toastSuccess(t('notification_setting.add_notification_pattern'));
       toastSuccess(t('notification_setting.add_notification_pattern'));
+      this.setState({ pathPattern: '', channel: '' });
     }
     }
     catch (err) {
     catch (err) {
       toastError(err);
       toastError(err);
@@ -99,7 +106,7 @@ class UserTriggerNotification extends React.Component {
                 </p>
                 </p>
               </td>
               </td>
               <td>
               <td>
-                <button type="button" className="btn btn-primary" onClick={this.onClickSubmit}>{t('add')}</button>
+                <button type="button" className="btn btn-primary" disabled={!this.validateForm()} onClick={this.onClickSubmit}>{t('add')}</button>
               </td>
               </td>
             </tr>
             </tr>
           </tbody>
           </tbody>