@ember-data/model 5.4.0-alpha.32 → 5.4.0-alpha.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -19
- package/unstable-preview-types/-private/attr.d.ts +171 -169
- package/unstable-preview-types/-private/attr.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/belongs-to.d.ts +181 -179
- package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -6
- package/unstable-preview-types/-private/errors.d.ts +290 -288
- package/unstable-preview-types/-private/has-many.d.ts +170 -168
- package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/hooks.d.ts +13 -11
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts +62 -60
- package/unstable-preview-types/-private/many-array.d.ts +193 -191
- package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -4
- package/unstable-preview-types/-private/model-methods.d.ts +34 -32
- package/unstable-preview-types/-private/model.d.ts +103 -100
- package/unstable-preview-types/-private/model.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/notify-changes.d.ts +8 -6
- package/unstable-preview-types/-private/promise-belongs-to.d.ts +47 -45
- package/unstable-preview-types/-private/promise-many-array.d.ts +129 -127
- package/unstable-preview-types/-private/promise-proxy-base.d.ts +35 -32
- package/unstable-preview-types/-private/record-state.d.ts +88 -86
- package/unstable-preview-types/-private/references/belongs-to.d.ts +473 -471
- package/unstable-preview-types/-private/references/has-many.d.ts +488 -486
- package/unstable-preview-types/-private/schema-provider.d.ts +27 -25
- package/unstable-preview-types/-private/util.d.ts +11 -9
- package/unstable-preview-types/-private.d.ts +12 -10
- package/unstable-preview-types/hooks.d.ts +5 -3
- package/unstable-preview-types/index.d.ts +75 -46
- package/unstable-preview-types/migration-support.d.ts +11 -9
|
@@ -1,306 +1,308 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="ember-source/types" />
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
declare const ArrayProxyWithCustomOverrides: new <T>() => ArrayProxyWithCustomOverrides<T>;
|
|
19
|
-
/**
|
|
20
|
-
Holds validation errors for a given record, organized by attribute names.
|
|
21
|
-
|
|
22
|
-
This class is not directly instantiable.
|
|
23
|
-
|
|
24
|
-
Every `Model` has an `errors` property that is an instance of
|
|
25
|
-
`Errors`. This can be used to display validation error
|
|
26
|
-
messages returned from the server when a `record.save()` rejects.
|
|
27
|
-
|
|
28
|
-
For Example, if you had a `User` model that looked like this:
|
|
29
|
-
|
|
30
|
-
```app/models/user.js
|
|
31
|
-
import Model, { attr } from '@ember-data/model';
|
|
32
|
-
|
|
33
|
-
export default class UserModel extends Model {
|
|
34
|
-
@attr('string') username;
|
|
35
|
-
@attr('string') email;
|
|
1
|
+
declare module '@ember-data/model/-private/errors' {
|
|
2
|
+
/// <reference types="ember-source/types" />
|
|
3
|
+
/// <reference types="ember-source/types" />
|
|
4
|
+
import { type NativeArray } from '@ember/array';
|
|
5
|
+
import ArrayProxy from '@ember/array/proxy';
|
|
6
|
+
import type RecordState from '@ember-data/model/-private/record-state';
|
|
7
|
+
type ValidationError = {
|
|
8
|
+
attribute: string;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
@module @ember-data/model
|
|
13
|
+
*/
|
|
14
|
+
interface ArrayProxyWithCustomOverrides<T> extends Omit<ArrayProxy<T>, 'clear' | 'content'> {
|
|
15
|
+
content: NativeArray<T>;
|
|
16
|
+
clear(): void;
|
|
17
|
+
_has(name: string): boolean;
|
|
36
18
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```javascript
|
|
41
|
-
let user = store.createRecord('user', {
|
|
42
|
-
username: 'tomster',
|
|
43
|
-
email: 'invalidEmail'
|
|
44
|
-
});
|
|
45
|
-
user.save();
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Your backend would be expected to return an error response that described
|
|
49
|
-
the problem, so that error messages can be generated on the app.
|
|
50
|
-
|
|
51
|
-
API responses will be translated into instances of `Errors` differently,
|
|
52
|
-
depending on the specific combination of adapter and serializer used. You
|
|
53
|
-
may want to check the documentation or the source code of the libraries
|
|
54
|
-
that you are using, to know how they expect errors to be communicated.
|
|
55
|
-
|
|
56
|
-
Errors can be displayed to the user by accessing their property name
|
|
57
|
-
to get an array of all the error objects for that property. Each
|
|
58
|
-
error object is a JavaScript object with two keys:
|
|
59
|
-
|
|
60
|
-
- `message` A string containing the error message from the backend
|
|
61
|
-
- `attribute` The name of the property associated with this error message
|
|
62
|
-
|
|
63
|
-
```handlebars
|
|
64
|
-
<label>Username: <Input @value={{@model.username}} /> </label>
|
|
65
|
-
{{#each @model.errors.username as |error|}}
|
|
66
|
-
<div class="error">
|
|
67
|
-
{{error.message}}
|
|
68
|
-
</div>
|
|
69
|
-
{{/each}}
|
|
70
|
-
|
|
71
|
-
<label>Email: <Input @value={{@model.email}} /> </label>
|
|
72
|
-
{{#each @model.errors.email as |error|}}
|
|
73
|
-
<div class="error">
|
|
74
|
-
{{error.message}}
|
|
75
|
-
</div>
|
|
76
|
-
{{/each}}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
You can also access the special `messages` property on the error
|
|
80
|
-
object to get an array of all the error strings.
|
|
81
|
-
|
|
82
|
-
```handlebars
|
|
83
|
-
{{#each @model.errors.messages as |message|}}
|
|
84
|
-
<div class="error">
|
|
85
|
-
{{message}}
|
|
86
|
-
</div>
|
|
87
|
-
{{/each}}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
@class Errors
|
|
91
|
-
@public
|
|
92
|
-
@extends Ember.ArrayProxy
|
|
93
|
-
*/
|
|
94
|
-
declare class Errors extends ArrayProxyWithCustomOverrides<ValidationError> {
|
|
95
|
-
__record: {
|
|
96
|
-
currentState: RecordState;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
@property errorsByAttributeName
|
|
100
|
-
@type {MapWithDefault}
|
|
101
|
-
@private
|
|
102
|
-
*/
|
|
103
|
-
get errorsByAttributeName(): Map<string, NativeArray<ValidationError>>;
|
|
104
|
-
/**
|
|
105
|
-
Returns errors for a given attribute
|
|
19
|
+
declare const ArrayProxyWithCustomOverrides: new <T>() => ArrayProxyWithCustomOverrides<T>;
|
|
20
|
+
/**
|
|
21
|
+
Holds validation errors for a given record, organized by attribute names.
|
|
106
22
|
|
|
107
|
-
|
|
108
|
-
let user = store.createRecord('user', {
|
|
109
|
-
username: 'tomster',
|
|
110
|
-
email: 'invalidEmail'
|
|
111
|
-
});
|
|
112
|
-
user.save().catch(function(){
|
|
113
|
-
user.errors.errorsFor('email'); // returns:
|
|
114
|
-
// [{attribute: "email", message: "Doesn't look like a valid email."}]
|
|
115
|
-
});
|
|
116
|
-
```
|
|
23
|
+
This class is not directly instantiable.
|
|
117
24
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
@return {Array}
|
|
122
|
-
*/
|
|
123
|
-
errorsFor(attribute: string): NativeArray<ValidationError>;
|
|
124
|
-
/**
|
|
125
|
-
An array containing all of the error messages for this
|
|
126
|
-
record. This is useful for displaying all errors to the user.
|
|
25
|
+
Every `Model` has an `errors` property that is an instance of
|
|
26
|
+
`Errors`. This can be used to display validation error
|
|
27
|
+
messages returned from the server when a `record.save()` rejects.
|
|
127
28
|
|
|
128
|
-
|
|
129
|
-
{{#each @model.errors.messages as |message|}}
|
|
130
|
-
<div class="error">
|
|
131
|
-
{{message}}
|
|
132
|
-
</div>
|
|
133
|
-
{{/each}}
|
|
134
|
-
```
|
|
29
|
+
For Example, if you had a `User` model that looked like this:
|
|
135
30
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
@type {Array}
|
|
139
|
-
*/
|
|
140
|
-
messages: string[];
|
|
141
|
-
/**
|
|
142
|
-
@property content
|
|
143
|
-
@type {Array}
|
|
144
|
-
@private
|
|
145
|
-
*/
|
|
146
|
-
get content(): NativeArray<ValidationError>;
|
|
147
|
-
/**
|
|
148
|
-
@method unknownProperty
|
|
149
|
-
@private
|
|
150
|
-
*/
|
|
151
|
-
unknownProperty(attribute: string): NativeArray<ValidationError> | undefined;
|
|
152
|
-
/**
|
|
153
|
-
Total number of errors.
|
|
31
|
+
```app/models/user.js
|
|
32
|
+
import Model, { attr } from '@ember-data/model';
|
|
154
33
|
|
|
155
|
-
|
|
156
|
-
@
|
|
157
|
-
@
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
`true` if we have no errors.
|
|
34
|
+
export default class UserModel extends Model {
|
|
35
|
+
@attr('string') username;
|
|
36
|
+
@attr('string') email;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
And you attempted to save a record that did not validate on the backend:
|
|
162
40
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
|
|
171
|
-
the record and transition the record into an `invalid` state.
|
|
41
|
+
```javascript
|
|
42
|
+
let user = store.createRecord('user', {
|
|
43
|
+
username: 'tomster',
|
|
44
|
+
email: 'invalidEmail'
|
|
45
|
+
});
|
|
46
|
+
user.save();
|
|
47
|
+
```
|
|
172
48
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
let errors = user.errors;
|
|
49
|
+
Your backend would be expected to return an error response that described
|
|
50
|
+
the problem, so that error messages can be generated on the app.
|
|
176
51
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
'Cannot contain your name'
|
|
182
|
-
]);
|
|
52
|
+
API responses will be translated into instances of `Errors` differently,
|
|
53
|
+
depending on the specific combination of adapter and serializer used. You
|
|
54
|
+
may want to check the documentation or the source code of the libraries
|
|
55
|
+
that you are using, to know how they expect errors to be communicated.
|
|
183
56
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// { attribute: 'password', message: 'Must be at least 12 characters' },
|
|
188
|
-
// { attribute: 'password', message: 'Must contain at least one symbol' },
|
|
189
|
-
// { attribute: 'password', message: 'Cannot contain your name' },
|
|
190
|
-
// ]
|
|
57
|
+
Errors can be displayed to the user by accessing their property name
|
|
58
|
+
to get an array of all the error objects for that property. Each
|
|
59
|
+
error object is a JavaScript object with two keys:
|
|
191
60
|
|
|
192
|
-
|
|
193
|
-
|
|
61
|
+
- `message` A string containing the error message from the backend
|
|
62
|
+
- `attribute` The name of the property associated with this error message
|
|
194
63
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
@public
|
|
203
|
-
@param {string} attribute - the property name of an attribute or relationship
|
|
204
|
-
@param {string[]|string} messages - an error message or array of error messages for the attribute
|
|
205
|
-
*/
|
|
206
|
-
add(attribute: string, messages: string[] | string): void;
|
|
207
|
-
/**
|
|
208
|
-
@method _findOrCreateMessages
|
|
209
|
-
@private
|
|
210
|
-
*/
|
|
211
|
-
_findOrCreateMessages(attribute: string, messages: string | string[]): ValidationError[];
|
|
212
|
-
/**
|
|
213
|
-
Manually removes all errors for a given member from the record.
|
|
214
|
-
This will transition the record into a `valid` state, and
|
|
215
|
-
triggers the `becameValid` event and lifecycle method.
|
|
64
|
+
```handlebars
|
|
65
|
+
<label>Username: <Input @value={{@model.username}} /> </label>
|
|
66
|
+
{{#each @model.errors.username as |error|}}
|
|
67
|
+
<div class="error">
|
|
68
|
+
{{error.message}}
|
|
69
|
+
</div>
|
|
70
|
+
{{/each}}
|
|
216
71
|
|
|
217
|
-
|
|
72
|
+
<label>Email: <Input @value={{@model.email}} /> </label>
|
|
73
|
+
{{#each @model.errors.email as |error|}}
|
|
74
|
+
<div class="error">
|
|
75
|
+
{{error.message}}
|
|
76
|
+
</div>
|
|
77
|
+
{{/each}}
|
|
78
|
+
```
|
|
218
79
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
errors.add('phone', ['error-1', 'error-2']);
|
|
80
|
+
You can also access the special `messages` property on the error
|
|
81
|
+
object to get an array of all the error strings.
|
|
222
82
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
83
|
+
```handlebars
|
|
84
|
+
{{#each @model.errors.messages as |message|}}
|
|
85
|
+
<div class="error">
|
|
86
|
+
{{message}}
|
|
87
|
+
</div>
|
|
88
|
+
{{/each}}
|
|
89
|
+
```
|
|
229
90
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
@
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
91
|
+
@class Errors
|
|
92
|
+
@public
|
|
93
|
+
@extends Ember.ArrayProxy
|
|
94
|
+
*/
|
|
95
|
+
declare class Errors extends ArrayProxyWithCustomOverrides<ValidationError> {
|
|
96
|
+
__record: {
|
|
97
|
+
currentState: RecordState;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
@property errorsByAttributeName
|
|
101
|
+
@type {MapWithDefault}
|
|
102
|
+
@private
|
|
103
|
+
*/
|
|
104
|
+
get errorsByAttributeName(): Map<string, NativeArray<ValidationError>>;
|
|
105
|
+
/**
|
|
106
|
+
Returns errors for a given attribute
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
let user = store.createRecord('user', {
|
|
110
|
+
username: 'tomster',
|
|
111
|
+
email: 'invalidEmail'
|
|
112
|
+
});
|
|
113
|
+
user.save().catch(function(){
|
|
114
|
+
user.errors.errorsFor('email'); // returns:
|
|
115
|
+
// [{attribute: "email", message: "Doesn't look like a valid email."}]
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
@method errorsFor
|
|
120
|
+
@public
|
|
121
|
+
@param {String} attribute
|
|
122
|
+
@return {Array}
|
|
123
|
+
*/
|
|
124
|
+
errorsFor(attribute: string): NativeArray<ValidationError>;
|
|
125
|
+
/**
|
|
126
|
+
An array containing all of the error messages for this
|
|
127
|
+
record. This is useful for displaying all errors to the user.
|
|
128
|
+
|
|
129
|
+
```handlebars
|
|
130
|
+
{{#each @model.errors.messages as |message|}}
|
|
131
|
+
<div class="error">
|
|
132
|
+
{{message}}
|
|
133
|
+
</div>
|
|
134
|
+
{{/each}}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
@property messages
|
|
138
|
+
@public
|
|
139
|
+
@type {Array}
|
|
140
|
+
*/
|
|
141
|
+
messages: string[];
|
|
142
|
+
/**
|
|
143
|
+
@property content
|
|
144
|
+
@type {Array}
|
|
145
|
+
@private
|
|
146
|
+
*/
|
|
147
|
+
get content(): NativeArray<ValidationError>;
|
|
148
|
+
/**
|
|
149
|
+
@method unknownProperty
|
|
150
|
+
@private
|
|
151
|
+
*/
|
|
152
|
+
unknownProperty(attribute: string): NativeArray<ValidationError> | undefined;
|
|
153
|
+
/**
|
|
154
|
+
Total number of errors.
|
|
155
|
+
|
|
156
|
+
@property length
|
|
157
|
+
@type {Number}
|
|
158
|
+
@public
|
|
159
|
+
@readOnly
|
|
160
|
+
*/
|
|
161
|
+
/**
|
|
162
|
+
`true` if we have no errors.
|
|
163
|
+
|
|
164
|
+
@property isEmpty
|
|
165
|
+
@type {Boolean}
|
|
166
|
+
@public
|
|
167
|
+
@readOnly
|
|
168
|
+
*/
|
|
169
|
+
isEmpty: boolean;
|
|
170
|
+
/**
|
|
171
|
+
Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
|
|
172
|
+
the record and transition the record into an `invalid` state.
|
|
173
|
+
|
|
174
|
+
Example
|
|
175
|
+
```javascript
|
|
176
|
+
let errors = user.errors;
|
|
177
|
+
|
|
178
|
+
// add multiple errors
|
|
179
|
+
errors.add('password', [
|
|
180
|
+
'Must be at least 12 characters',
|
|
181
|
+
'Must contain at least one symbol',
|
|
182
|
+
'Cannot contain your name'
|
|
183
|
+
]);
|
|
184
|
+
|
|
185
|
+
errors.errorsFor('password');
|
|
186
|
+
// =>
|
|
187
|
+
// [
|
|
188
|
+
// { attribute: 'password', message: 'Must be at least 12 characters' },
|
|
189
|
+
// { attribute: 'password', message: 'Must contain at least one symbol' },
|
|
190
|
+
// { attribute: 'password', message: 'Cannot contain your name' },
|
|
191
|
+
// ]
|
|
192
|
+
|
|
193
|
+
// add a single error
|
|
194
|
+
errors.add('username', 'This field is required');
|
|
195
|
+
|
|
196
|
+
errors.errorsFor('username');
|
|
197
|
+
// =>
|
|
198
|
+
// [
|
|
199
|
+
// { attribute: 'username', message: 'This field is required' },
|
|
200
|
+
// ]
|
|
201
|
+
```
|
|
202
|
+
@method add
|
|
203
|
+
@public
|
|
204
|
+
@param {string} attribute - the property name of an attribute or relationship
|
|
205
|
+
@param {string[]|string} messages - an error message or array of error messages for the attribute
|
|
206
|
+
*/
|
|
207
|
+
add(attribute: string, messages: string[] | string): void;
|
|
208
|
+
/**
|
|
209
|
+
@method _findOrCreateMessages
|
|
210
|
+
@private
|
|
211
|
+
*/
|
|
212
|
+
_findOrCreateMessages(attribute: string, messages: string | string[]): ValidationError[];
|
|
213
|
+
/**
|
|
214
|
+
Manually removes all errors for a given member from the record.
|
|
215
|
+
This will transition the record into a `valid` state, and
|
|
216
|
+
triggers the `becameValid` event and lifecycle method.
|
|
217
|
+
|
|
218
|
+
Example:
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
let errors = user.errors;
|
|
222
|
+
errors.add('phone', ['error-1', 'error-2']);
|
|
223
|
+
|
|
224
|
+
errors.errorsFor('phone');
|
|
225
|
+
// =>
|
|
226
|
+
// [
|
|
227
|
+
// { attribute: 'phone', message: 'error-1' },
|
|
228
|
+
// { attribute: 'phone', message: 'error-2' },
|
|
229
|
+
// ]
|
|
230
|
+
|
|
231
|
+
errors.remove('phone');
|
|
232
|
+
|
|
233
|
+
errors.errorsFor('phone');
|
|
234
|
+
// => undefined
|
|
235
|
+
```
|
|
236
|
+
@method remove
|
|
237
|
+
@public
|
|
238
|
+
@param {string} member - the property name of an attribute or relationship
|
|
239
|
+
*/
|
|
240
|
+
remove(attribute: string): void;
|
|
241
|
+
/**
|
|
242
|
+
Manually clears all errors for the record.
|
|
243
|
+
This will transition the record into a `valid` state, and
|
|
244
|
+
will trigger the `becameValid` event and lifecycle method.
|
|
245
|
+
|
|
246
|
+
Example:
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
let errors = user.errors;
|
|
250
|
+
errors.add('username', ['error-a']);
|
|
251
|
+
errors.add('phone', ['error-1', 'error-2']);
|
|
252
|
+
|
|
253
|
+
errors.errorsFor('username');
|
|
254
|
+
// =>
|
|
255
|
+
// [
|
|
256
|
+
// { attribute: 'username', message: 'error-a' },
|
|
257
|
+
// ]
|
|
258
|
+
|
|
259
|
+
errors.errorsFor('phone');
|
|
260
|
+
// =>
|
|
261
|
+
// [
|
|
262
|
+
// { attribute: 'phone', message: 'error-1' },
|
|
263
|
+
// { attribute: 'phone', message: 'error-2' },
|
|
264
|
+
// ]
|
|
265
|
+
|
|
266
|
+
errors.clear();
|
|
267
|
+
|
|
268
|
+
errors.errorsFor('username');
|
|
269
|
+
// => undefined
|
|
270
|
+
|
|
271
|
+
errors.errorsFor('phone');
|
|
272
|
+
// => undefined
|
|
273
|
+
|
|
274
|
+
errors.messages
|
|
275
|
+
// => []
|
|
276
|
+
```
|
|
277
|
+
@method clear
|
|
278
|
+
@public
|
|
279
|
+
*/
|
|
280
|
+
clear(): void;
|
|
281
|
+
/**
|
|
282
|
+
Checks if there are error messages for the given attribute.
|
|
283
|
+
|
|
284
|
+
```app/controllers/user/edit.js
|
|
285
|
+
import Controller from '@ember/controller';
|
|
286
|
+
import { action } from '@ember/object';
|
|
287
|
+
|
|
288
|
+
export default class UserEditController extends Controller {
|
|
289
|
+
@action
|
|
290
|
+
save(user) {
|
|
291
|
+
if (user.errors.has('email')) {
|
|
292
|
+
return alert('Please update your email before attempting to save.');
|
|
293
|
+
}
|
|
294
|
+
user.save();
|
|
292
295
|
}
|
|
293
|
-
user.save();
|
|
294
296
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
@method has
|
|
300
|
+
@public
|
|
301
|
+
@param {String} attribute
|
|
302
|
+
@return {Boolean} true if there some errors on given attribute
|
|
303
|
+
*/
|
|
304
|
+
has(attribute: string): boolean;
|
|
305
|
+
}
|
|
306
|
+
export default Errors;
|
|
307
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
308
|
+
}
|