mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
14 lines
614 B
CoffeeScript
14 lines
614 B
CoffeeScript
# Mainly useful for adding a blank option that works with AngularJS
|
|
# Angular doesn't seem to understand the blank option generated by rails
|
|
# using the include_blank flag on select helper.
|
|
angular.module("admin.indexUtils").directive "ofnSelect", ->
|
|
restrict: 'E'
|
|
scope:
|
|
data: "="
|
|
replace: true
|
|
template: (element, attrs) ->
|
|
valueAttr = attrs.valueAttr || 'id'
|
|
textAttr = attrs.textAttr || 'name'
|
|
blank = if attrs.includeBlank? then "<option value=''>#{attrs.includeBlank}</option>" else ""
|
|
return "<select ng-options='e.#{valueAttr} as e.#{textAttr} for e in data'>#{blank}</select>"
|