Skip to content

Commit

Permalink
fix(common(js)): initialize search field with pre-selected option
Browse files Browse the repository at this point in the history
This is required because of regression in AngularJS Material.

Fixes #5044
  • Loading branch information
cgx committed Jun 17, 2020
1 parent 97add60 commit 1432600
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion UI/WebServerResources/js/Common/sgSearch.directive.js
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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);
Expand Down

0 comments on commit 1432600

Please sign in to comment.