Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(5515): Fix validation documentation #5693

Merged
merged 1 commit into from
Oct 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions misc/tutorial/322_validation.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@name Tutorial: 322 Validation
@description

<div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development.
<div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development.
There will almost certainly be breaking api changes, or there are major outstanding bugs.</div>

Feature ui.grid.validate allows validating cells after they are changed. To enable, you must include the
Expand All @@ -27,8 +27,8 @@ Some custom validators come with the feature and are:
To define a new validator you should use the {@link
api/ui.grid.validate.service:uiGridValidateService#methods_setValidator setValidator} method.

To add a validator to a column you just need to add a `validators` property to its `colDef`
object, containing a property for each validator you want to add. The name of the property
To add a validator to a column you just need to add a `validators` property to its `colDef`
object, containing a property for each validator you want to add. The name of the property
will set the validator and the value of the property will be treated as an argument by the validator function.

When a field does not pass validation it gets a `invalid` class so you can customize it via css.
Expand All @@ -40,12 +40,12 @@ The feature adds 2 templates to ui-grid:

## External Factory

In case you have an external service providing validators, you can add a function calling said service
In case you have an external service providing validators, you can add a function calling said service
by setting an external validator factory function via {@link
api/ui.grid.validate.service:uiGridValidateService#methods_setExternalFactoryFunction setExternalFactoryFunction}.

Please be advised that external validators should accept the same parameters (or at least an ordered subset) as
our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
our validators do (`oldValue`, `newValue`, `rowEntity`, `colDef`);

@example
<example module="app">
Expand All @@ -59,10 +59,10 @@ our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
});

app.controller('MainCtrl', ['$scope', '$http', '$window', 'uiGridValidateService', function ($scope, $http, $window, uiGridValidateService) {

uiGridValidateService.setValidator('startWith',
function(argument) {
return function(newValue, oldValue, rowEntity, colDef) {
return function(oldValue, newValue, rowEntity, colDef) {
if (!newValue) {
return true; // We should not test for existence here
} else {
Expand All @@ -74,12 +74,12 @@ our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
return 'You can only insert names starting with: "' + argument + '"';
}
);

$scope.gridOptions = { enableCellEditOnFocus: true };

$scope.gridOptions.columnDefs = [
{ name: 'id', enableCellEdit: false, width: '10%' },
{ name: 'name', displayName: 'Name (editable)', width: '20%',
{ name: 'name', displayName: 'Name (editable)', width: '20%',
validators: {required: true, startWith: 'M'}, cellTemplate: 'ui-grid/cellTitleValidator' }
];

Expand All @@ -92,7 +92,7 @@ our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
$scope.gridApi = gridApi;
gridApi.validate.on.validationFailed($scope,function(rowEntity, colDef, newValue, oldValue){
$window.alert('rowEntity: '+ rowEntity + '\n' +
'colDef: ' + colDef + '\n' +
'colDef: ' + colDef + '\n' +
'newValue: ' + newValue + '\n' +
'oldValue: ' + oldValue);
});
Expand All @@ -116,4 +116,4 @@ our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
height: 450px;
}
</file>
</example>
</example>