Description
My use-case is as follows:
I got a parentform with a dynamically generated list of childforms in it. The childforms are generated based on data fetched from a server.
Each time I receive new data from the server, I'd like to say that, since we have new data, the parentform should be made pristine. This is, after all, the new "truth" we have to work with right now: none of the childforms has been modified.
However, I did not find a proper way to reset the modified state of the parentform via angular-input-modified
.
Example
I tried the following to tackle this issue:
parentform.html
<form name="parentform" bs-modifiable="true">
<div ng-if="childforms.length" ng-repeat="childform in childforms" ng-form="{{ childform.id }}">
<!-- contents of childform -->
</div>
</form>
parentformDirective.js
...
link: function ($scope) {
$scope.$watch('childforms', function () {
$scope.parentform.$setPristine();
});
...
}
...
This seems nice, but I ran into trouble in the following scenario:
- Modify one of my childforms
angular-input-modified
now marks my parentform asmodified: true
- A new set of childforms comes in from the server
- The modified childform is missing from this set of childforms
Now, because of my $scope.parentform.$setPristine
call, angular-input-modified
does update the $pristine
and $dirty
variables of my parentform, but does not update the modified: true
property on my parentform.
This is probably due to the fact that the modified childform is not in the new set of childforms and the onModifiedStateChange
function does not update the appropriate properties on the parentform object (see https://github.com/betsol/angular-input-modified/blob/master/src/directive/form.js#L98).
Is there any other way to do this? If not, I think this is a bug in the onModifiedStateChanged
function.