fix(common(js)): initialize search field with pre-selected option

This is required because of regression in AngularJS Material.

Fixes #5044
This commit is contained in:
Francis Lachapelle
2020-06-17 17:25:21 -04:00
parent 97add602df
commit 1432600fae
@@ -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);