Skip to content

Commit 486fa1e

Browse files
Stefan SchubertStefan Schubert
authored andcommitted
fix nextControlErrorKey
it returns now only the error key not a concatenation of prefix, field name and errorkey
1 parent be5142a commit 486fa1e

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

dist/formgroup.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ export declare class TypedFormGroup<T> extends FormGroup {
4343
*/
4444
isValidatorRegistered(name: Extract<keyof T, string>, validatorName: string): boolean;
4545
/**
46-
* Returns an error key for the next error (<controlName>.<errorKey>).
46+
* Returns an error key for the next error.
4747
*
4848
* @param name control key of the form group
49-
* @param prefix to be prepend to the error key
5049
*/
51-
nextControlErrorKey(name: Extract<keyof T, string>, prefix?: string): string;
50+
nextControlErrorKey(name: Extract<keyof T, string>): string;
5251
/**
5352
* Dispatches errors to this control and to child controls using given error map.
5453
*

dist/index.es.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,11 @@ var TypedFormGroup = /** @class */ (function (_super) {
198198
this.registeredValidatorsMap[name].some(function (errorKey) { return errorKey === validatorName; }));
199199
};
200200
/**
201-
* Returns an error key for the next error (<controlName>.<errorKey>).
201+
* Returns an error key for the next error.
202202
*
203203
* @param name control key of the form group
204-
* @param prefix to be prepend to the error key
205204
*/
206-
TypedFormGroup.prototype.nextControlErrorKey = function (name, prefix) {
205+
TypedFormGroup.prototype.nextControlErrorKey = function (name) {
207206
var control = this.get(name);
208207
if (control && control.errors) {
209208
// try client side keys first for correct order
@@ -214,7 +213,7 @@ var TypedFormGroup = /** @class */ (function (_super) {
214213
error = Object.keys(control.errors).shift();
215214
}
216215
if (error) {
217-
return "" + (prefix ? prefix + "." : '') + name + "." + error;
216+
return error;
218217
}
219218
}
220219
return '';

dist/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,11 @@ var TypedFormGroup = /** @class */ (function (_super) {
202202
this.registeredValidatorsMap[name].some(function (errorKey) { return errorKey === validatorName; }));
203203
};
204204
/**
205-
* Returns an error key for the next error (<controlName>.<errorKey>).
205+
* Returns an error key for the next error.
206206
*
207207
* @param name control key of the form group
208-
* @param prefix to be prepend to the error key
209208
*/
210-
TypedFormGroup.prototype.nextControlErrorKey = function (name, prefix) {
209+
TypedFormGroup.prototype.nextControlErrorKey = function (name) {
211210
var control = this.get(name);
212211
if (control && control.errors) {
213212
// try client side keys first for correct order
@@ -218,7 +217,7 @@ var TypedFormGroup = /** @class */ (function (_super) {
218217
error = Object.keys(control.errors).shift();
219218
}
220219
if (error) {
221-
return "" + (prefix ? prefix + "." : '') + name + "." + error;
220+
return error;
222221
}
223222
}
224223
return '';

src/formgroup.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface NestedType {
1111
deepValue: string;
1212
}
1313

14-
test('Test FormGroupControl creation', () => {
14+
test('Test FormGroupControl creation #1', () => {
1515
const factory = new BaseFormControlFactory<TestType>(
1616
{ value: 'testValue', nested: { deepValue: 'deepTestValue' } },
1717
{ value: [['req', Validators.required]], nested: [] }
@@ -60,14 +60,14 @@ test('Test FormGroupControl creation', () => {
6060
expect(nestedGroup.hasControlErrors('deepValue')).toBe(true);
6161
expect(group.isValidatorRegistered('value', 'required')).toBe(false);
6262
expect(nestedGroup.isValidatorRegistered('deepValue', 'required')).toBe(false);
63-
expect(group.nextControlErrorKey('value')).toBe('value.req');
64-
expect(nestedGroup.nextControlErrorKey('deepValue')).toBe('deepValue.req');
63+
expect(group.nextControlErrorKey('value')).toBe('req');
64+
expect(nestedGroup.nextControlErrorKey('deepValue')).toBe('req');
6565

6666
valueControl.setErrors({ other: 'Other Error!' });
67-
expect(group.nextControlErrorKey('value')).toBe('value.other');
67+
expect(group.nextControlErrorKey('value')).toBe('other');
6868
});
6969

70-
test('Test FormGroupControl creation', () => {
70+
test('Test FormGroupControl creation #2', () => {
7171
const nestedFactory = new BaseFormControlFactory<NestedType>(
7272
{ deepValue: 'deepTestValue' },
7373
{ deepValue: [['req', Validators.required]] }

src/formgroup.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,11 @@ export class TypedFormGroup<T> extends FormGroup {
8888
}
8989

9090
/**
91-
* Returns an error key for the next error (<controlName>.<errorKey>).
91+
* Returns an error key for the next error.
9292
*
9393
* @param name control key of the form group
94-
* @param prefix to be prepend to the error key
9594
*/
96-
nextControlErrorKey(name: Extract<keyof T, string>, prefix?: string): string {
95+
nextControlErrorKey(name: Extract<keyof T, string>): string {
9796
const control = this.get(name);
9897
if (control && control.errors) {
9998
// try client side keys first for correct order
@@ -105,7 +104,7 @@ export class TypedFormGroup<T> extends FormGroup {
105104
error = Object.keys(control.errors).shift();
106105
}
107106
if (error) {
108-
return `${prefix ? `${prefix}.` : ''}${name}.${error}`;
107+
return error;
109108
}
110109
}
111110
return '';

0 commit comments

Comments
 (0)