0

We have a mover directive that uses 2 list controls. The problem is that when I simply click on an item in the assigned items list, it makes my form dirty. I tried the following solution in the directive controller onChanged event (which is called by the second list ng-change):

 $scope.onChanged = function (assigned) {
                    var currentState = $scope.form.$dirty;
                    $scope.selectedItem = assigned[0];
                    if (currentState === false)
                        $scope.form.$setPristine();
                }

However, the currentState is already true, so my code does nothing. How can I prevent the clicking in the list control to set form's dirty status? I found two related questions How can I exclude controls from making form Dirty? and How can I denote which input fields have changed in AngularJS but it's not clear to me if I should try either of these solutions. The code checks for $scope.form.$dirty in a few places, so the best solution is somehow to make sure that clicking on the list doesn't make it dirty. I also have noDirty directive which I haven't yet tried applying to that list. I'm going to try that now.

Community
  • 1
  • 1
Naomi
  • 718
  • 1
  • 9
  • 28

1 Answers1

0

The solution I implemented for now is the following change in the directive:

var directive = {
            controller: ['$scope', '$timeout', function ($scope, $timeout) {
                $scope.upDisabled = true;
                $scope.downDisabled = true;
                $scope.assigned = null;
                $timeout(function () {
                    $scope.form.assignedList.$pristine = false;
                });

based on last answer in that thread Prevent input from setting form $dirty angularjs. In my quick limited test it seems to work. I originally tried to just use our noDirtyCheck directive on the list, but somehow it didn't work in my first try, so I already switched to this solution.

Community
  • 1
  • 1
Naomi
  • 718
  • 1
  • 9
  • 28