SearchForm.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <script>
  2. import Vue from 'vue'
  3. import router from 'vuejs/route'
  4. import { mapState, mapActions } from 'vuex'
  5. export default {
  6. router,
  7. props: ['form'],
  8. data() {
  9. return {
  10. template: null,
  11. keys: "",
  12. autocomplete: ""
  13. }
  14. },
  15. methods: {
  16. ...mapActions({
  17. newSearch: 'Search/newSearch'
  18. }),
  19. submit() {
  20. console.log("search clicked", this.keys, this.autocomplete);
  21. this.newSearch(this.keys, this.autocomplete)
  22. .then(() => {
  23. this.$router.push({name:'base'})
  24. });
  25. },
  26. onAutoCompleteSelect(event, ui){
  27. event.preventDefault();
  28. // console.log('autoCompleteSelect', event, ui);
  29. this.keys = ui.item.label
  30. this.autocomplete = ui.item.value
  31. }
  32. },
  33. beforeMount() {
  34. // console.log('SearchForm beforeMount');
  35. if(this._props.form){
  36. // console.log('SearchForm beforeMount if this._props.form ok');
  37. this.template = Vue.compile(this._props.form)
  38. // https://github.com/vuejs/vue/issues/9911
  39. this.$options.staticRenderFns = [];
  40. this._staticTrees = [];
  41. this.template.staticRenderFns.map(fn => (this.$options.staticRenderFns.push(fn)));
  42. }
  43. },
  44. watch: {
  45. keys(){
  46. console.log('keys changed', this.keys);
  47. }
  48. },
  49. mounted(){
  50. // console.log('SearchForm mounted');
  51. Drupal.attachBehaviors(this.$el);
  52. // Catch the jquery ui events for autocmplete widget
  53. jQuery(this.$el.querySelector('#edit-search')).on('autocompleteselect', this.onAutoCompleteSelect);
  54. },
  55. render(h) {
  56. // console.log('searchForm render');
  57. if(!this.template){
  58. return h('span', 'Loading ...')
  59. }else{
  60. return this.template.render.call(this)
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. </style>