From 79f1e7b0ee9e3e8b0716b8e5defd81827585983f Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Wed, 29 Aug 2018 17:31:47 +0100 Subject: [PATCH] Update ui-select value as the user types. --- .../app/views/user/settings/user-affiliations.pug | 6 ++++++ .../affiliations/components/affiliationForm.coffee | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/services/web/app/views/user/settings/user-affiliations.pug b/services/web/app/views/user/settings/user-affiliations.pug index 3527beb05a..d997d7952d 100644 --- a/services/web/app/views/user/settings/user-affiliations.pug +++ b/services/web/app/views/user/settings/user-affiliations.pug @@ -202,6 +202,8 @@ script(type="text/ng-template", id="affiliationFormTpl") ) {{ $select.selected.name }} ui-select-choices( repeat="university in $ctrl.universities | filter: $select.search" + refresh="$ctrl.handleFreeformInputChange($select, 'name');" + refresh-delay="10" ) span( ng-bind="university.name" @@ -219,6 +221,8 @@ script(type="text/ng-template", id="affiliationFormTpl") ) {{ $select.selected }} ui-select-choices( repeat="role in $ctrl.roles | filter: $select.search" + refresh="$ctrl.handleFreeformInputChange($select);" + refresh-delay="10" ) span( ng-bind="role" @@ -237,6 +241,8 @@ script(type="text/ng-template", id="affiliationFormTpl") ) {{ $select.selected }} ui-select-choices( repeat="department in $ctrl.departments | filter: $select.search" + refresh="$ctrl.handleFreeformInputChange($select);" + refresh-delay="10" ) span( ng-bind="department" diff --git a/services/web/public/coffee/main/affiliations/components/affiliationForm.coffee b/services/web/public/coffee/main/affiliations/components/affiliationForm.coffee index 1c0c7d6229..1f018595ec 100644 --- a/services/web/public/coffee/main/affiliations/components/affiliationForm.coffee +++ b/services/web/public/coffee/main/affiliations/components/affiliationForm.coffee @@ -11,6 +11,18 @@ define [ ctrl.addUniversityToSelection = (universityName) -> { name: universityName, isUserSuggested: true } + ctrl.handleFreeformInputChange = ($select, propertyToMatch) -> + if !$select.search? or $select.search == "" + return + resultingItem = $select.search + if $select.tagging?.fct? + resultingItem = $select.tagging.fct $select.search + if propertyToMatch? + matchingItem = _.find $select.items, (item) -> item[propertyToMatch] == $select.search + if matchingItem? + resultingItem = matchingItem + $select.searchInput.scope().$broadcast "uis:select", resultingItem + # Populates the countries dropdown UserAffiliationsDataService .getCountries()