Просмотр исходного кода

when SearchTypeahead in searchPage change, move searched page

yusuketk 7 лет назад
Родитель
Сommit
b25f03cb0b
1 измененных файлов с 30 добавлено и 12 удалено
  1. 30 12
      src/client/js/components/SearchPage/SearchForm.js

+ 30 - 12
src/client/js/components/SearchPage/SearchForm.js

@@ -15,8 +15,19 @@ export default class SearchForm extends React.Component {
     };
     };
 
 
     this.onSearchError = this.onSearchError.bind(this);
     this.onSearchError = this.onSearchError.bind(this);
-    this.handleChange = this.handleChange.bind(this);
     this.onSubmit = this.onSubmit.bind(this);
     this.onSubmit = this.onSubmit.bind(this);
+    this.onChange = this.onChange.bind(this);
+  }
+
+  search() {
+    if (this.state.searchedKeyword != this.state.keyword) {
+      this.props.onSearchFormChanged({
+        keyword: this.state.keyword
+      });
+      this.setState({
+        searchedKeyword: this.state.keyword
+      });
+    }
   }
   }
 
 
   onSearchError(err) {
   onSearchError(err) {
@@ -25,22 +36,28 @@ export default class SearchForm extends React.Component {
     });
     });
   }
   }
 
 
-  handleChange(selected) {
-    const page = selected[0];  // should be single page selected
+  onSubmit(event) {
+    // // get the closest form element
+    // const elem = this.refs.form;
+    // const form = elem.closest('form');
+    // // submit with jQuery
+    // $(form).submit();
+    if (event !== '') {
+      event.preventDefault();
+    }
+    console.log(event);
+  }
+
+  onChange(selected) {
+    const page = selected[0];
+    this.search({keyword: page});
+
     // navigate to page
     // navigate to page
     if (page != null) {
     if (page != null) {
       window.location = page.path;
       window.location = page.path;
     }
     }
   }
   }
 
 
-  onSubmit(query) {
-    // get the closest form element
-    const elem = this.refs.form;
-    const form = elem.closest('form');
-    // submit with jQuery
-    $(form).submit();
-  }
-
   getHelpElement() {
   getHelpElement() {
     return (
     return (
       <table className="table m-1 search-help">
       <table className="table m-1 search-help">
@@ -74,10 +91,11 @@ export default class SearchForm extends React.Component {
       <form ref='form' className="form form-group input-group" onSubmit={this.onSubmit}>
       <form ref='form' className="form form-group input-group" onSubmit={this.onSubmit}>
         <SearchTypeahead
         <SearchTypeahead
           crowi={this.props.crowi}
           crowi={this.props.crowi}
-          onChange={this.handleChange}
+          onChange={this.onChange}
           onSubmit={this.onSubmit}
           onSubmit={this.onSubmit}
           onSearchError={this.onSearchError}
           onSearchError={this.onSearchError}
           emptyLabel={emptyLabel}
           emptyLabel={emptyLabel}
+          promptText={this.getHelpElement()}
           keywordOnInit={this.state.keyword}
           keywordOnInit={this.state.keyword}
         />
         />
           <span className="input-group-btn">
           <span className="input-group-btn">