diff --git a/scripts/langindex.json b/scripts/langindex.json index bc790fe92..a271644f8 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -2407,6 +2407,7 @@ "core.search.allcategories": "local_moodlemobileapp", "core.search.allcourses": "search", "core.search.empty": "local_moodlemobileapp", + "core.search.err_minlength": "form", "core.search.filtercategories": "local_moodlemobileapp", "core.search.filtercourses": "local_moodlemobileapp", "core.search.filterheader": "search", diff --git a/src/core/features/courses/pages/list/list.html b/src/core/features/courses/pages/list/list.html index 47b406bc2..35b91bb56 100644 --- a/src/core/features/courses/pages/list/list.html +++ b/src/core/features/courses/pages/list/list.html @@ -26,7 +26,7 @@ + searchArea="CoreCoursesSearch" [lengthCheck]="1" /> diff --git a/src/core/features/search/components/search-box/core-search-box.html b/src/core/features/search/components/search-box/core-search-box.html index 054ab491a..c10f9d2ea 100644 --- a/src/core/features/search/components/search-box/core-search-box.html +++ b/src/core/features/search/components/search-box/core-search-box.html @@ -2,8 +2,7 @@ - + + + + {{ 'core.search.err_minlength' | translate : {'$a': {'format': lengthCheck} } }} + + diff --git a/src/core/features/search/components/search-box/search-box.scss b/src/core/features/search/components/search-box/search-box.scss index 8afdc8c3d..fa22c8742 100644 --- a/src/core/features/search/components/search-box/search-box.scss +++ b/src/core/features/search/components/search-box/search-box.scss @@ -35,8 +35,6 @@ } } - - .core-search-history { max-height: calc(-120px + 80vh); overflow-y: auto; diff --git a/src/core/features/search/components/search-box/search-box.ts b/src/core/features/search/components/search-box/search-box.ts index c013928d3..1db5989c8 100644 --- a/src/core/features/search/components/search-box/search-box.ts +++ b/src/core/features/search/components/search-box/search-box.ts @@ -62,6 +62,7 @@ export class CoreSearchBoxComponent implements OnInit { searchText = ''; history: CoreSearchHistoryDBRecord[] = []; historyShown = false; + showLengthAlert = false; constructor() { this.onSubmit = new EventEmitter(); @@ -86,14 +87,17 @@ export class CoreSearchBoxComponent implements OnInit { * @param e Event. */ submitForm(e?: Event): void { - e && e.preventDefault(); - e && e.stopPropagation(); + e?.preventDefault(); + e?.stopPropagation(); if (this.searchText.length < this.lengthCheck) { - // The view should handle this case, but we check it here too just in case. + this.showLengthAlert = true; + return; } + this.showLengthAlert = false; + if (this.searchArea) { this.saveSearchToHistory(this.searchText); } @@ -147,6 +151,7 @@ export class CoreSearchBoxComponent implements OnInit { clearForm(): void { this.searched = ''; this.searchText = ''; + this.showLengthAlert = false; this.onClear.emit(); } diff --git a/src/core/features/search/lang.json b/src/core/features/search/lang.json index 5a17626cd..d1fbb00cd 100644 --- a/src/core/features/search/lang.json +++ b/src/core/features/search/lang.json @@ -8,5 +8,6 @@ "globalsearch": "Global search", "noresults": "No results for \"{{$a}}\"", "noresultshelp": "Check for typos or try using different keywords", + "err_minlength": "You must enter at least {{$a.format}} characters here.", "resultby": "By {{$a}}" } diff --git a/src/core/features/tag/pages/search/search.html b/src/core/features/tag/pages/search/search.html index 40a682ac7..d04d7e819 100644 --- a/src/core/features/tag/pages/search/search.html +++ b/src/core/features/tag/pages/search/search.html @@ -19,7 +19,7 @@ + autocorrect="off" [spellcheck]="false" [autoFocus]="false" [lengthCheck]="1" searchArea="CoreTag" />