From 1432600fae5440c82456a3fcf33e12627496475c Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 17 Jun 2020 17:25:21 -0400 Subject: [PATCH] fix(common(js)): initialize search field with pre-selected option This is required because of regression in AngularJS Material. Fixes #5044 --- UI/WebServerResources/js/Common/sgSearch.directive.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/UI/WebServerResources/js/Common/sgSearch.directive.js b/UI/WebServerResources/js/Common/sgSearch.directive.js index 3325475db..5b3c6bb5e 100644 --- a/UI/WebServerResources/js/Common/sgSearch.directive.js +++ b/UI/WebServerResources/js/Common/sgSearch.directive.js @@ -40,6 +40,7 @@ var mdInputEl = tElement.find('md-input-container'), inputEl = tElement.find('input'), selectEl = tElement.find('md-select'), + optionEl = tElement.find('md-option'), buttonEl = tElement.find('md-button'); inputEl.attr('ng-model', '$sgSearchController.searchText'); @@ -58,7 +59,7 @@ } return function postLink(scope, iElement, iAttr, controller) { - var compiledButtonEl = iElement.find('button'); + var compiledButtonEl = iElement.find('button'), selectedOption; // Retrive the form and input names to check the form's validity in the controller controller.formName = iElement.attr('name'); @@ -73,6 +74,14 @@ // Associate callback to controller controller.doSearch = $parse(iElement.attr('sg-search')); + // Initialize searchField model to first selected option + selectedOption = _.find(optionEl, function (el) { + return el.getAttribute('selected'); + }); + if (selectedOption) { + controller.searchField = selectedOption.getAttribute('value'); + } + // Reset the input field when cancelling the search if (buttonEl && compiledButtonEl) { compiledButtonEl.on('click', controller.cancelSearch);