|
| 1 | +{{! |
| 2 | + This file is part of Moodle - http://moodle.org/ |
| 3 | +
|
| 4 | + Moodle is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation, either version 3 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | +
|
| 9 | + Moodle is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +}} |
| 17 | +{{! |
| 18 | + @template core/search_input_navbar_inline |
| 19 | +
|
| 20 | + Inline navbar search input for desktop. Always visible, no collapse or toggle. |
| 21 | +
|
| 22 | + Example context (json): |
| 23 | + { |
| 24 | + "action": "https://moodle.local/search/index.php", |
| 25 | + "inputname": "q", |
| 26 | + "searchstring": "Search", |
| 27 | + "grouplabel": "Site-wide search", |
| 28 | + "hiddenfields": [ |
| 29 | + { |
| 30 | + "name": "context", |
| 31 | + "value": "1" |
| 32 | + } |
| 33 | + ] |
| 34 | + } |
| 35 | +}} |
| 36 | +<div id="searchinput-navbar-{{uniqid}}" class="search-input-inline"> |
| 37 | + <form role="search" |
| 38 | + {{#grouplabel}}aria-label="{{{ grouplabel }}}"{{/grouplabel}} |
| 39 | + autocomplete="off" |
| 40 | + action="{{{ action }}}" |
| 41 | + method="get" |
| 42 | + accept-charset="utf-8" |
| 43 | + class="searchform-navbar"> |
| 44 | + {{#hiddenfields}} |
| 45 | + <input type="hidden" name="{{ name }}" value="{{ value }}"> |
| 46 | + {{/hiddenfields}} |
| 47 | + <label for="searchinput-{{uniqid}}" class="visually-hidden">{{{ searchstring }}}</label> |
| 48 | + <div class="input-group"> |
| 49 | + <button type="submit" class="input-group-text border-0 pe-0"> |
| 50 | + {{#pix}} a/search, core {{/pix}} |
| 51 | + <span class="visually-hidden">{{#str}} performsearch, search {{/str}}</span> |
| 52 | + </button> |
| 53 | + <input type="text" |
| 54 | + id="searchinput-{{uniqid}}" |
| 55 | + class="form-control border-0 ps-1" |
| 56 | + placeholder="{{{ searchstring }}}" |
| 57 | + name="{{{ inputname }}}" |
| 58 | + data-region="input" |
| 59 | + autocomplete="off"> |
| 60 | + </div> |
| 61 | + </form> |
| 62 | +</div> |
| 63 | + |
| 64 | +{{#js}} |
| 65 | +require([], function() { |
| 66 | + const wrapper = document.getElementById('searchinput-navbar-{{uniqid}}'); |
| 67 | + const form = wrapper.querySelector('.searchform-navbar'); |
| 68 | + const input = wrapper.querySelector('[data-region="input"]'); |
| 69 | +
|
| 70 | + form.addEventListener('submit', (e) => { |
| 71 | + if (input.value.trim() === '') { |
| 72 | + e.preventDefault(); |
| 73 | + } |
| 74 | + }); |
| 75 | +}); |
| 76 | +{{/js}} |
0 commit comments