Files
openfoodnetwork/app/assets/javascripts/admin/index_utils/directives/ofn-select.js.coffee

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>"