Skip to content

Commit 3883975

Browse files
authored
Merge pull request #829 from dxc-technology/jialecl-textInputError
[Major]Error behaviour when empty string in textInput
2 parents caddd22 + 2a4ebda commit 3883975

File tree

13 files changed

+101
-88
lines changed

13 files changed

+101
-88
lines changed

projects/dxc-ngx-cdk-site/src/app/components/examples/date-input/date-properties/date-properties.component.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@
9494
the component. An object including the string value, the error and the
9595
date value will be emitted. An example of this object is:
9696
{{ "{" }} <code>value: value, error: error, date: date</code>{{ "}" }}. If
97-
the string value is a valid date, <code>error</code> will be null. Also,
98-
if the string value is not a valid date, <code>date</code> will be null.
97+
the string value is a valid date, <code>error</code> will be undefined.
98+
Also, if the string value is not a valid date, <code>date</code> will be
99+
undefined.
99100
</td>
100101
</tr>
101102
<tr>
@@ -108,8 +109,8 @@
108109
{{ "{" }}
109110
<code>value: value, error: error, date: date</code>
110111
{{ "}" }}. If the string value is a valid date, <code>error</code> will be
111-
null. Also, if the string value is not a valid date,
112-
<code>date</code> will be null.
112+
undefined. Also, if the string value is not a valid date,
113+
<code>date</code> will be undefined.
113114
</td>
114115
</tr>
115116
<tr>

projects/dxc-ngx-cdk-site/src/app/components/examples/number-input/number-properties/number-properties.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
is lower than min, the onBlur and onChange functions will be called with
7171
the current value and an internal error informing that the current value
7272
is not correct. If a valid state is reached, the error parameter will be
73-
null in both events.
73+
undefined in both events.
7474
</td>
7575
</tr>
7676
<tr>
@@ -80,7 +80,7 @@
8080
Maximum value allowed by the number input. If the typed value by the user
8181
surpasses max, the onBlur and onChange functions will be called with the
8282
current value and an internal error informing that the current value is
83-
not correct. If a valid state is reached, the error parameter will be null
83+
not correct. If a valid state is reached, the error parameter will be undefined
8484
in both events.
8585
</td>
8686
</tr>
@@ -110,7 +110,7 @@
110110
value entered is not valid) will be passed to this function. An example of
111111
this object is: {{ "{ " }}
112112
<code>value: value, error: error</code>
113-
{{ "}" }}. If there is no error, error will be null.
113+
{{ "}" }}. If there is no error, error will be undefined.
114114
</td>
115115
</tr>
116116
<tr>
@@ -121,7 +121,7 @@
121121
including the value and the error (if the value entered is not valid) will
122122
be passed to this function. An example of this object is: {{ "{" }}
123123
<code>value: value, error: error</code>
124-
{{ "}" }}. If there is no error, error will be null.
124+
{{ "}" }}. If there is no error, error will be undefined.
125125
</td>
126126
</tr>
127127
<tr>

projects/dxc-ngx-cdk-site/src/app/components/examples/password-input/password-properties/password-properties.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
value entered is not valid) will be passed to this function. An example of
6060
this object is:
6161
{{ "{" }} <code>value: value, error: error</code>{{ "}" }}. If there is no
62-
error, error will be null.
62+
error, error will be undefined.
6363
</td>
6464
</tr>
6565
<tr>
@@ -71,7 +71,7 @@
7171
valid) will be passed to this function. An example of this object is:
7272
{{ "{" }}
7373
<code>value: value, error: error</code>
74-
{{ "}" }}. If there is no error, error will be null.
74+
{{ "}" }}. If there is no error, error will be undefined.
7575
</td>
7676
</tr>
7777
<tr>
@@ -93,7 +93,7 @@
9393
pattern, the onBlur and onChange functions will be called with the current
9494
value and an internal error informing that this value does not match the
9595
pattern. If the pattern is met, the error parameter of both events will be
96-
null.
96+
undefined.
9797
</td>
9898
</tr>
9999
<tr>
@@ -106,7 +106,7 @@
106106
onChange functions will be called with the current value and an internal
107107
error informing that the value length does not comply the specified range.
108108
If a valid length is reached, the error parameter of both events will be
109-
null.
109+
undefined.
110110
</td>
111111
</tr>
112112
<tr>
@@ -119,7 +119,7 @@
119119
onChange functions will be called with the current value and an internal
120120
error informing that the value length does not comply the specified range.
121121
If a valid length is reached, the error parameter of both events will be
122-
null.
122+
undefined.
123123
</td>
124124
</tr>
125125
<tr>

projects/dxc-ngx-cdk-site/src/app/components/examples/text-input/text-input-properties/text-input-properties.component.html

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@
5555
<td>error: string</td>
5656
<td></td>
5757
<td>
58-
If it is defined, the component will change its appearance, showing the
59-
error below the input component. If it is not defined, the error messages
60-
will be created and managed internally.
58+
If it is a defined value and also a truthy string, the component will
59+
change its appearance, showing the error below the input component. If the
60+
defined value is an empty string, it will reserve a space below the
61+
component for a future error, but it would not change its look. In case of
62+
being undefined or undefined, both the appearance and the space for the error
63+
message would not be modified.
6164
</td>
6265
</tr>
6366
<tr>
@@ -81,20 +84,22 @@
8184
<td>onChange: EventEmitter</td>
8285
<td></td>
8386
<td>
84-
This function will be called when the user types within the input. The new
85-
value will be passed as a parameter.
87+
This event will emit when the user types within the input element
88+
of the component. An object including the current value and the error (if
89+
the value entered is not valid) will be passed to this function. An
90+
example of this object is: {{ "{" }} value: value, error: error {{ "}" }}. If there is no
91+
error, error will not be defined.
8692
</td>
8793
</tr>
8894
<tr>
8995
<td>onBlur: EventEmitter</td>
9096
<td></td>
9197
<td>
92-
This function will be called when the input loses the focus. An object
98+
This event will emit when the input element loses the focus. An object
9399
including the input value and the error (if the value entered is not
94-
valid) will be passed to this function. An example of this object is:
95-
{{ "{" }}
96-
<code>value: value, error: error</code>
97-
{{ "}" }}. If there is no error, error will be null.
100+
valid) will be passed to this function. An example of this object is: {{ "{" }}
101+
value: value, error: error {{ "}" }}. If there is no error, error will not be
102+
defined.
98103
</td>
99104
</tr>
100105
<tr>
@@ -121,7 +126,7 @@
121126
does not match the pattern, the onBlur function will be called with the
122127
value entered and the error informing that the value does not match the
123128
pattern as parameters. If the pattern is accomplished, the error parameter
124-
will be null.
129+
will be undefined.
125130
</td>
126131
</tr>
127132
<tr>
@@ -149,7 +154,7 @@
149154
onChange functions will be called with the current value and an internal
150155
error informing that the value length does not comply the specified range.
151156
If a valid length is reached, the error parameter of both events will be
152-
null.
157+
undefined.
153158
</td>
154159
</tr>
155160
<tr>
@@ -162,7 +167,7 @@
162167
onChange functions will be called with the current value and an internal
163168
error informing that the value length does not comply the specified range.
164169
If a valid length is reached, the error parameter of both events will be
165-
null.
170+
undefined.
166171
</td>
167172
</tr>
168173
<tr>

projects/dxc-ngx-cdk/src/lib/dxc-date-input/dxc-date-input.component.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe("DxcDate", () => {
138138
fireEvent.input(input, { target: { value: newValue } });
139139
expect(onChange).toHaveBeenCalledWith({
140140
value: newValue,
141-
error: null,
141+
error: undefined,
142142
date: newMockDate,
143143
});
144144
expect(screen.getByDisplayValue(newValue));
@@ -180,7 +180,7 @@ describe("DxcDate", () => {
180180
fireEvent.input(input, { target: { value: newValue } });
181181
expect(onChange).toHaveBeenCalledWith({
182182
value: newValue,
183-
error: null,
183+
error: undefined,
184184
date: newMockDate,
185185
});
186186
expect(screen.getByDisplayValue(newValue));
@@ -189,7 +189,7 @@ describe("DxcDate", () => {
189189
fireEvent.input(input, { target: { value: "04-10-1996" } });
190190
expect(onChange).toHaveBeenCalledWith({
191191
value: "04-10-1996",
192-
error: null,
192+
error: undefined,
193193
date: new Date("1996/10/04"),
194194
});
195195
expect(screen.getByDisplayValue("04-10-1996"));
@@ -237,7 +237,7 @@ describe("DxcDate", () => {
237237
fireEvent.input(input, { target: { value: "1995/12/03" } });
238238
expect(onChange).toHaveBeenCalledWith({
239239
value: "1995/12/03",
240-
error: null,
240+
error: undefined,
241241
date: newMockDate,
242242
});
243243
input.focus();
@@ -290,8 +290,8 @@ describe("DxcDate", () => {
290290

291291
expect(onChange).toHaveBeenCalledWith({
292292
value: invalidValue,
293-
error: null,
294-
date: null,
293+
error: undefined,
294+
date: undefined,
295295
});
296296
});
297297

@@ -481,14 +481,14 @@ describe("DxcDate", () => {
481481
fireEvent.input(input, { target: { value: "03-10-1996" } });
482482
expect(onChange).toHaveBeenCalledWith({
483483
value: "03-10-1996",
484-
error: null,
484+
error: undefined,
485485
date: new Date("1996/10/03"),
486486
});
487487
expect(screen.getByDisplayValue("03-12-1995"));
488488
fireEvent.blur(input);
489489
waitFor(() => {
490490
expect(onBlur).toHaveBeenCalledWith({
491-
error: null,
491+
error: undefined,
492492
value: "03-12-1995",
493493
date: new Date("1995/12/03"),
494494
});

projects/dxc-ngx-cdk/src/lib/dxc-date-input/dxc-date-input.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ export class DxcDateInputComponent implements OnInit {
147147

148148
/**
149149
* This event will emit in case the user types within the input element of the component. An object including the string value,
150-
* the error and the date value will be emitted. If the string value is a valid date, error will be null.
151-
* Also, if the string value is not a valid date, date will be null.
150+
* the error and the date value will be emitted. If the string value is a valid date, error will be undefined.
151+
* Also, if the string value is not a valid date, date will be undefined.
152152
*/
153153
@Output() onChange = new EventEmitter<EmittedValue>();
154154
/**
155155
* This event will emit in case the input element loses the focus. An object including the string value,
156-
* the error and the date value will be emitted. If the string value is a valid date, error will be null.
157-
* Also, if the string value is not a valid date, date will be null.
156+
* the error and the date value will be emitted. If the string value is a valid date, error will be undefined.
157+
* Also, if the string value is not a valid date, date will be undefined.
158158
*/
159159
@Output() onBlur = new EventEmitter<EmittedValue>();
160160
/**
@@ -283,7 +283,7 @@ export class DxcDateInputComponent implements OnInit {
283283
let _dateReturn = {
284284
value: value.value,
285285
error: value.error,
286-
date: _dateValue.isValid() ? _dateValue.toDate() : null,
286+
date: _dateValue.isValid() ? _dateValue.toDate() : undefined,
287287
};
288288
this.onChange.emit(_dateReturn);
289289

@@ -302,7 +302,7 @@ export class DxcDateInputComponent implements OnInit {
302302
this.onBlur.emit({
303303
value: event.value,
304304
error: event.error,
305-
date: _dateValue.isValid() ? _dateValue.toDate() : null,
305+
date: _dateValue.isValid() ? _dateValue.toDate() : undefined,
306306
});
307307
if (!this.controlled) {
308308
this.renderedValue = event.value;
@@ -315,7 +315,7 @@ export class DxcDateInputComponent implements OnInit {
315315
let _stringValue = this.getDateStringValue(value, this.format);
316316
let _dateReturn = {
317317
value: _stringValue,
318-
date: value.isValid() ? value.toDate() : null,
318+
date: value.isValid() ? value.toDate() : undefined,
319319
error: this.dxcInputRef.error,
320320
};
321321
this.onChange.emit(_dateReturn);

projects/dxc-ngx-cdk/src/lib/dxc-number-input/dxc-number-input.component.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("DxcNumberInputComponent", () => {
8080
input.focus();
8181
expect(input).toHaveFocus();
8282
fireEvent.click(screen.getByLabelText("Increment"));
83-
expect(onChange).toHaveBeenCalledWith({ value: "10", error: null });
83+
expect(onChange).toHaveBeenCalledWith({ value: "10", error: undefined });
8484
});
8585

8686
test("decrease should call onChange in dxc-number", async () => {
@@ -105,7 +105,7 @@ describe("DxcNumberInputComponent", () => {
105105
input.focus();
106106
expect(input).toHaveFocus();
107107
fireEvent.click(screen.getByLabelText("Decrement"));
108-
expect(onChange).toHaveBeenCalledWith({ value: "5", error: null });
108+
expect(onChange).toHaveBeenCalledWith({ value: "5", error: undefined });
109109
});
110110

111111
test("controlled dxc-number", async () => {
@@ -135,7 +135,7 @@ describe("DxcNumberInputComponent", () => {
135135
expect(input.max).toBe("100");
136136
expect(screen.getByDisplayValue("4")).toBeTruthy();
137137
fireEvent.input(input, { target: { value: "10" } });
138-
expect(onChange).toHaveBeenCalledWith({ value: "10", error: null });
138+
expect(onChange).toHaveBeenCalledWith({ value: "10", error: undefined });
139139
expect(screen.getByDisplayValue("4")).toBeTruthy();
140140
});
141141

@@ -170,7 +170,7 @@ describe("DxcNumberInputComponent", () => {
170170
expect(input.max).toBe("100");
171171
expect(screen.getByDisplayValue("4"));
172172
fireEvent.input(input, { target: { value: "10" } });
173-
expect(onChange).toHaveBeenCalledWith({ value: "10", error: null });
173+
expect(onChange).toHaveBeenCalledWith({ value: "10", error: undefined });
174174
expect(screen.getByDisplayValue("4"));
175175
fireEvent.blur(input);
176176
waitFor(() => {

projects/dxc-ngx-cdk/src/lib/dxc-number-input/dxc-number-input.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
7575
* lower than min, the onBlur and onChange functions will be called with
7676
* the current value and an internal error informing that the current
7777
* value is not correct. If a valid state is reached, the error parameter
78-
* will be null in both events.
78+
* will be undefined in both events.
7979
*/
8080
@Input()
8181
get min(): number {
@@ -90,7 +90,7 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
9090
* surpasses max, the onBlur and onChange functions will be called with
9191
* the current value and an internal error informing that the current
9292
* value is not correct. If a valid state is reached, the error parameter
93-
* will be null in both events.
93+
* will be undefined in both events.
9494
*/
9595
@Input()
9696
get max(): number {
@@ -174,14 +174,14 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
174174
* This event will emit in case the user types within the input
175175
* element of the component. An object including the current value and
176176
* the error (if the value entered is not valid) will be passed to this
177-
* function. If there is no error, error will be null.
177+
* function. If there is no error, error will be undefined.
178178
*/
179179
@Output() onChange = new EventEmitter<OnChangeEvent>();
180180
/**
181181
* This event will emit in case the number loses the focus.
182182
* An object including the input value and the error (if the value
183183
* entered is not valid) will be passed to this function. If there is no error,
184-
* error will be null.
184+
* error will be undefined.
185185
*/
186186
@Output() onBlur = new EventEmitter<OnBlurEvent>();
187187
@ViewChild("dxcInputRef", { static: false })
@@ -305,7 +305,7 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
305305
currentValue = coerceNumberProperty(this.value);
306306
}
307307
let calculatedValue = this.calculateMinus(currentValue);
308-
this.handleOnChange({ value: calculatedValue.toString(), error: null });
308+
this.handleOnChange({ value: calculatedValue.toString(), error: undefined });
309309
this.dxcInputRef.inputRef.nativeElement.focus();
310310
}
311311

@@ -318,7 +318,7 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
318318
currentValue = coerceNumberProperty(this.value);
319319
}
320320
let calculatedValue = this.calculatePlus(currentValue);
321-
this.handleOnChange({ value: calculatedValue.toString(), error: null });
321+
this.handleOnChange({ value: calculatedValue.toString(), error: undefined });
322322
this.dxcInputRef.inputRef.nativeElement.focus();
323323
}
324324

0 commit comments

Comments
 (0)