Procházet zdrojové kódy

Update ui-select value as the user types.

Paulo Reis před 8 roky
rodič
revize
79f1e7b0ee

+ 6 - 0
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"

+ 12 - 0
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()