mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Restricting number of tags for tag rules to one
This commit is contained in:
@@ -7,10 +7,15 @@ angular.module("admin.utils").directive "tagsWithTranslation", ($timeout) ->
|
||||
tagListAttr: "@?"
|
||||
findTags: "&"
|
||||
form: '=?'
|
||||
onTagAdded: "&"
|
||||
onTagRemoved: "&"
|
||||
max: "="
|
||||
link: (scope, element, attrs) ->
|
||||
scope.findTags = undefined unless attrs.hasOwnProperty("findTags")
|
||||
scope.limitReached = false
|
||||
|
||||
compileTagList = ->
|
||||
scope.limitReached = scope.object[scope.tagsAttr].length >= scope.max if scope.max != undefined
|
||||
scope.object[scope.tagListAttr] = (tag.text for tag in scope.object[scope.tagsAttr]).join(",")
|
||||
|
||||
$timeout ->
|
||||
@@ -21,10 +26,12 @@ angular.module("admin.utils").directive "tagsWithTranslation", ($timeout) ->
|
||||
compileTagList()
|
||||
|
||||
scope.tagAdded = ->
|
||||
scope.onTagAdded()
|
||||
compileTagList()
|
||||
|
||||
scope.tagRemoved = ->
|
||||
# For some reason the tags input doesn't mark the form
|
||||
# as dirty when a tag is removed, which breaks the save bar
|
||||
scope.form.$setDirty(true) if typeof scope.form isnt 'undefined'
|
||||
scope.onTagRemoved()
|
||||
compileTagList()
|
||||
|
||||
Reference in New Issue
Block a user