]> BookStack Code Mirror - bookstack/commitdiff
Updated entity-selector-popup to reset on selection
authorDan Brown <redacted>
Sat, 25 Jun 2022 13:13:17 +0000 (14:13 +0100)
committerDan Brown <redacted>
Sat, 25 Jun 2022 13:13:17 +0000 (14:13 +0100)
Better links the core selector component to the popup version, with new
public methods for direct controlling.

For #3528

resources/js/components/entity-selector-popup.js
resources/js/components/entity-selector.js
resources/views/entities/selector.blade.php

index 231f1021fcbe1158f7f7ba331276e6ba5ba68135..fb74fa5b829c8c14d625e335042e6e1d8e48df17 100644 (file)
@@ -7,9 +7,9 @@ class EntitySelectorPopup {
     setup() {
         this.elem = this.$el;
         this.selectButton = this.$refs.select;
-        this.searchInput = this.$refs.searchInput;
 
         window.EntitySelectorPopup = this;
+        this.selectorEl = this.$refs.selector;
 
         this.callback = null;
         this.selection = null;
@@ -22,13 +22,17 @@ class EntitySelectorPopup {
     show(callback) {
         this.callback = callback;
         this.elem.components.popup.show();
-        this.searchInput.focus();
+        this.getSelector().focusSearch();
     }
 
     hide() {
         this.elem.components.popup.hide();
     }
 
+    getSelector() {
+        return this.selectorEl.components['entity-selector'];
+    }
+
     onSelectButtonClick() {
         this.hide();
         if (this.selection !== null && this.callback) this.callback(this.selection);
@@ -36,6 +40,7 @@ class EntitySelectorPopup {
 
     onSelectionConfirm(entity) {
         this.hide();
+        this.getSelector().reset();
         if (this.callback && entity) this.callback(entity);
     }
 
index 6d9d06f860329b402c9166db51ffc646537ca988..e2596998aedea01a105b40496f1909c0d6b60f20 100644 (file)
@@ -87,6 +87,16 @@ class EntitySelector {
         }
     }
 
+    reset() {
+        this.searchInput.value = '';
+        this.showLoading();
+        this.initialLoad();
+    }
+
+    focusSearch() {
+        this.searchInput.focus();
+    }
+
     showLoading() {
         this.loading.style.display = 'block';
         this.resultsContainer.style.display = 'none';
index 5285b0ec46917e84b0deb43d0cce5bc8ac0473f3..45fae470795bf1c375ee587a27ddd7d6c143061a 100644 (file)
@@ -1,10 +1,11 @@
 <div class="form-group entity-selector-container">
     <div component="entity-selector"
+         refs="entity-selector-popup@selector"
          class="entity-selector {{$selectorSize ?? ''}}"
          option:entity-selector:entity-types="{{ $entityTypes ?? 'book,chapter,page' }}"
          option:entity-selector:entity-permission="{{ $entityPermission ?? 'view' }}">
         <input refs="entity-selector@input" type="hidden" name="{{$name}}" value="">
-        <input refs="entity-selector@search entity-selector-popup@searchInput" type="text" placeholder="{{ trans('common.search') }}" @if($autofocus ?? false) autofocus @endif>
+        <input refs="entity-selector@search" type="text" placeholder="{{ trans('common.search') }}" @if($autofocus ?? false) autofocus @endif>
         <div class="text-center loading" refs="entity-selector@loading">@include('common.loading-icon')</div>
         <div refs="entity-selector@results"></div>
         @if($showAdd ?? false)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.