<div class="form-group" ng-show="(currentItem.splitType == 0)"> <label class="col-md-6 col-lg-6 control-label">@Labels.remainingPercentage:</label> <div class="col-md-6 col-lg-6"> <div ng-show="(currentItem.splitType == 0)" class="input-group"> @*sm:number directive requires a model. Passing in currentItem to ng-model*@ <input type="text" name="profitCenterTotal" ng-model="currentItem" class="form-control" value="{{profitCenterTotal()}}" placeholder="0" data-sm:number data-sm:number-format data-accuracy="3" disabled/> <span class="input-group-addon">%</span> </div> <div class="field-validation-error"> <span ng-show="form.editItemProfitCenterForm.pcSplit1.$error.total">@String.Format(Messages.mustBeEqualTo, Labels.remainingPercentage, ("0" + Labels.percentSymbol))</span> </div> </div> </div> </div>When I try to create a new item, the Profit Controls tab comes highlighted in red (as invalid). It has the following control at the top
<div class="col-md-10 col-lg-10 points-box"> <div class="form-group"> <div class="col-md-6 col-lg-6"> <select class="form-control" ng-model="currentItem.prCtr1" ng-options="p.profitCenterNo as p.descrip for p in metaData.profitCenters | filter:filterProfitCenters1" id="prCtr1" name="prCtr1"> </select> </div> <div class="col-md-6 col-lg-6"> <div class="input-group"> <input type="text" name="pcSplit1" ng-model="currentItem.pcSplit1" class="form-control" placeholder="Allocation 1" data-sm:number data-sm:number-format data-accuracy="3"> <span class="input-group-addon" ng-show="(currentItem.splitType == 0)">%</span> </div> </div> </div>Even if I select percentage method and select 100% for the first profit center (and leave the rest 5 to be 0), I see the remaining as 0 and highlighted in red.
$scope.profitCenterTotal = function () { var total = 0; if ($scope.currentItem) { if ($scope.currentItem.splitType == 0) { total = ($scope.currentItem.pcSplit1 + $scope.currentItem.pcSplit2 + $scope.currentItem.pcSplit3 + $scope.currentItem.pcSplit4 + $scope.currentItem.pcSplit5 + $scope.currentItem.pcSplit6); if ($scope.form.editItemProfitCenterForm.pcSplit1.$dirty || $scope.form.editItemProfitCenterForm.pcSplit2.$dirty || $scope.form.editItemProfitCenterForm.pcSplit3.$dirty || $scope.form.editItemProfitCenterForm.pcSplit4.$dirty || $scope.form.editItemProfitCenterForm.pcSplit5.$dirty || $scope.form.editItemProfitCenterForm.pcSplit6.$dirty) { if (total == 100) { $scope.form.editItemProfitCenterForm.pcSplit1.$setValidity("total", true); } else { $scope.form.editItemProfitCenterForm.pcSplit1.$setValidity("total", false); } } else { $scope.form.editItemProfitCenterForm.pcSplit1.$setValidity("total", true); } } else { $scope.form.editItemProfitCenterForm.pcSplit1.$setValidity("total", true); } } return $filter('number')((100 - total), 4); };I don't like the fact that the code sets validity of the control - sounds like some weird code to me. Not sure of a better approach, though.