angular-ui/ui-grid

Row edit feature will save rows, despite them being invalid through the validation feature

Open

#5.320 aberto em 14 de abr. de 2016

Ver no GitHub
 (1 comment) (2 reactions) (0 assignees)JavaScript (2.496 forks)batch import
good first issue

Métricas do repositório

Stars
 (5.395 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

When using the row edit feature, validation will set the css class, but not prevent the saving of invalid data, which is unexpected.

I created a workaround by returning an empty promise to the setSavePromise function

$scope.saveRow = function(rowEntity) {
        var isValid = true;

        // check if the entity is invalid on any of its columns
        for (var i = 0; i < $scope.gridOptions.columnDefs.length; i++) {
          if ($scope.gridApi.validate.isInvalid(rowEntity, $scope.gridOptions.columnDefs[i]) !== undefined) {
            isValid = isValid && !$scope.gridApi.validate.isInvalid(rowEntity, $scope.gridOptions.columnDefs[i]);
          }
        }

        // if the entity is valid, then update. otherwise return an empty promise
        if (isValid) {
          var promise = SomeService.update(rowEntity).$promise;
          $scope.gridApi.rowEdit.setSavePromise(rowEntity, promise);


        } else {
          var promise = $q.defer();
          $scope.gridApi.rowEdit.setSavePromise(rowEntity, promise.promise);
          promise.resolve();
        }
      };

Guia do colaborador