Skip to content

Commit

Permalink
Implemented correct validation in prices grid
Browse files Browse the repository at this point in the history
  • Loading branch information
megafreeman committed Sep 8, 2017
1 parent e0ffed4 commit 7cb91fc
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion VirtoCommerce.PricingModule.Web/Scripts/blades/prices-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@
];

function addNewPrice(targetList) {
var newEntity = { productId: blade.itemId, list: 0, minQuantity: 1, currency: blade.currency, priceListId: blade.priceListId };
var newEntity = { productId: blade.itemId, list: '', minQuantity: 1, currency: blade.currency, priceListId: blade.priceListId };
targetList.push(newEntity);
$scope.validateGridData();
}

$scope.isListPriceValid = priceValidatorsService.isListPriceValid;
Expand All @@ -119,11 +120,35 @@

// ui-grid
$scope.setGridOptions = function (gridId, gridOptions) {
gridOptions.onRegisterApi = function (gridApi) {
$scope.gridApi = gridApi;

gridApi.edit.on.afterCellEdit($scope, function () {
//to process validation for all rows in grid.
//e.g. if we have two rows with the same count of min qty, both of this rows will be marked as error.
//when we change data to valid in one row, another one should became valid too.
//more info about ui-grid validation: https://github.com/angular-ui/ui-grid/issues/4152
$scope.validateGridData();
});

$scope.validateGridData();
};

$scope.gridOptions = gridOptions;
gridOptionExtension.tryExtendGridOptions(gridId, gridOptions);
return gridOptions;
};

$scope.validateGridData = function () {
if ($scope.gridApi) {
angular.forEach(blade.currentEntities, function (rowEntity) {
angular.forEach($scope.gridOptions.columnDefs, function (colDef) {
$scope.gridApi.grid.validate.runValidators(rowEntity, colDef, rowEntity[colDef.name], undefined, $scope.gridApi.grid)
});
});
}
};

// actions on load
blade.refresh();
}])
Expand Down

0 comments on commit 7cb91fc

Please sign in to comment.