mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-01 06:41:41 +00:00
Adapting taxon autocompleter to allow multiple selection of taxons
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
# Adapted from Spree's existing taxon autocompletion
|
||||
require: "ngModel"
|
||||
link: (scope,element,attrs,ngModel) ->
|
||||
scope: true
|
||||
link: (scope,element,attrs) ->
|
||||
multiple = scope.$eval attrs.multipleSelection
|
||||
placeholder = attrs.placeholder
|
||||
|
||||
setTimeout ->
|
||||
element.select2
|
||||
placeholder: "Category"
|
||||
multiple: false
|
||||
placeholder: placeholder
|
||||
multiple: multiple
|
||||
initSelection: (element, callback) ->
|
||||
callback Taxons.findByID(scope.product.category_id)
|
||||
if multiple
|
||||
callback Taxons.findByIDs(scope.product.category_id)
|
||||
else
|
||||
callback Taxons.findByID(scope.product.category_id)
|
||||
query: (query) ->
|
||||
query.callback { results: Taxons.findByTerm(query.term) }
|
||||
formatResult: (taxon) ->
|
||||
taxon.name
|
||||
formatSelection: (taxon) ->
|
||||
taxon.name
|
||||
element.on "change", ->
|
||||
scope.$apply ->
|
||||
ngModel.$setViewValue element.val()
|
||||
taxon.name
|
||||
Reference in New Issue
Block a user