2
2
@name Tutorial: 322 Validation
3
3
@description
4
4
5
- <div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development.
5
+ <div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development.
6
6
There will almost certainly be breaking api changes, or there are major outstanding bugs.</div>
7
7
8
8
Feature ui.grid.validate allows validating cells after they are changed. To enable, you must include the
@@ -27,8 +27,8 @@ Some custom validators come with the feature and are:
27
27
To define a new validator you should use the {@link
28
28
api/ui.grid.validate.service:uiGridValidateService#methods_setValidator setValidator} method.
29
29
30
- To add a validator to a column you just need to add a `validators` property to its `colDef`
31
- object, containing a property for each validator you want to add. The name of the property
30
+ To add a validator to a column you just need to add a `validators` property to its `colDef`
31
+ object, containing a property for each validator you want to add. The name of the property
32
32
will set the validator and the value of the property will be treated as an argument by the validator function.
33
33
34
34
When a field does not pass validation it gets a `invalid` class so you can customize it via css.
@@ -40,12 +40,12 @@ The feature adds 2 templates to ui-grid:
40
40
41
41
## External Factory
42
42
43
- In case you have an external service providing validators, you can add a function calling said service
43
+ In case you have an external service providing validators, you can add a function calling said service
44
44
by setting an external validator factory function via {@link
45
45
api/ui.grid.validate.service:uiGridValidateService#methods_setExternalFactoryFunction setExternalFactoryFunction}.
46
46
47
47
Please be advised that external validators should accept the same parameters (or at least an ordered subset) as
48
- our validators do (`newValue `, `oldValue `, `rowEntity`, `colDef`);
48
+ our validators do (`oldValue `, `newValue `, `rowEntity`, `colDef`);
49
49
50
50
@example
51
51
<example module="app">
@@ -59,10 +59,10 @@ our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
59
59
});
60
60
61
61
app.controller('MainCtrl', ['$scope', '$http', '$window', 'uiGridValidateService', function ($scope, $http, $window, uiGridValidateService) {
62
-
62
+
63
63
uiGridValidateService.setValidator('startWith',
64
64
function(argument) {
65
- return function(newValue, oldValue , rowEntity, colDef) {
65
+ return function(oldValue, newValue , rowEntity, colDef) {
66
66
if (!newValue) {
67
67
return true; // We should not test for existence here
68
68
} else {
@@ -74,12 +74,12 @@ our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
74
74
return 'You can only insert names starting with: "' + argument + '"';
75
75
}
76
76
);
77
-
77
+
78
78
$scope.gridOptions = { enableCellEditOnFocus: true };
79
79
80
80
$scope.gridOptions.columnDefs = [
81
81
{ name: 'id', enableCellEdit: false, width: '10%' },
82
- { name: 'name', displayName: 'Name (editable)', width: '20%',
82
+ { name: 'name', displayName: 'Name (editable)', width: '20%',
83
83
validators: {required: true, startWith: 'M'}, cellTemplate: 'ui-grid/cellTitleValidator' }
84
84
];
85
85
@@ -92,7 +92,7 @@ our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
92
92
$scope.gridApi = gridApi;
93
93
gridApi.validate.on.validationFailed($scope,function(rowEntity, colDef, newValue, oldValue){
94
94
$window.alert('rowEntity: '+ rowEntity + '\n' +
95
- 'colDef: ' + colDef + '\n' +
95
+ 'colDef: ' + colDef + '\n' +
96
96
'newValue: ' + newValue + '\n' +
97
97
'oldValue: ' + oldValue);
98
98
});
@@ -116,4 +116,4 @@ our validators do (`newValue`, `oldValue`, `rowEntity`, `colDef`);
116
116
height: 450px;
117
117
}
118
118
</file>
119
- </example>
119
+ </example>
0 commit comments