Add select2WatchNgModel directive

- Select2 components cannot handle ng-model correctly: they do not update if the ng-model change. Add a directive to watch the ng-model and update the component value
This commit is contained in:
Jean-Baptiste Bellet
2021-05-31 09:43:59 +02:00
parent 58a96c6500
commit 303bf5420e
3 changed files with 22 additions and 11 deletions

View File

@@ -0,0 +1,8 @@
angular.module("ofn.admin").directive "select2WatchNgModel", () ->
restrict: 'E'
scope: true
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
ngModel.$render = () ->
newValue = ngModel.$viewValue;
element.children(".select2").select2("val", newValue)