Skip to content

Commit f08b12b

Browse files
samhere06mohas22
andauthored
error message on a field disappears when you click outside (#301)
Co-authored-by: mohas22 <[email protected]>
1 parent c140c57 commit f08b12b

File tree

18 files changed

+191
-99
lines changed

18 files changed

+191
-99
lines changed

packages/angular-sdk-components/src/lib/_components/field/currency/currency.component.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,25 @@ export class CurrencyComponent implements OnInit, OnDestroy {
198198
}
199199

200200
fieldOnBlur(event: any) {
201-
const actionsApi = this.pConn$?.getActionsApi();
202-
const propName = this.pConn$?.getStateProps().value;
203-
let value = event?.target?.value;
204-
value = value?.substring(1);
205-
// replacing thousand separator with empty string as not required in api call
206-
const thousandSep = this.thousandSeparator === '.' ? '\\.' : this.thousandSeparator;
207-
let regExp = new RegExp(String.raw`${thousandSep}`, 'g');
208-
value = value?.replace(regExp, '');
209-
// replacing decimal separator with '.'
210-
if (this.decimalSeparator !== '.') {
211-
regExp = new RegExp(String.raw`${this.decimalSeparator}`, 'g');
212-
value = value.replace(regExp, '.');
201+
const oldVal = this.value$ ?? '';
202+
const isValueChanged = event.target.value.toString() !== oldVal.toString();
203+
204+
if (isValueChanged) {
205+
const actionsApi = this.pConn$?.getActionsApi();
206+
const propName = this.pConn$?.getStateProps().value;
207+
let value = event?.target?.value;
208+
value = value?.substring(1);
209+
// replacing thousand separator with empty string as not required in api call
210+
const thousandSep = this.thousandSeparator === '.' ? '\\.' : this.thousandSeparator;
211+
let regExp = new RegExp(String.raw`${thousandSep}`, 'g');
212+
value = value?.replace(regExp, '');
213+
// replacing decimal separator with '.'
214+
if (this.decimalSeparator !== '.') {
215+
regExp = new RegExp(String.raw`${this.decimalSeparator}`, 'g');
216+
value = value.replace(regExp, '.');
217+
}
218+
handleEvent(actionsApi, 'changeNblur', propName, value);
213219
}
214-
handleEvent(actionsApi, 'changeNblur', propName, value);
215220
}
216221

217222
getErrorMessage() {

packages/angular-sdk-components/src/lib/_components/field/decimal/decimal.component.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,26 @@ export class DecimalComponent implements OnInit, OnDestroy {
209209
}
210210

211211
fieldOnBlur(event: any) {
212-
const actionsApi = this.pConn$?.getActionsApi();
213-
const propName = this.pConn$?.getStateProps().value;
214-
let value = event?.target?.value;
215-
// replacing thousand separator with empty string as not required in api call
216-
if (this.configProps$.showGroupSeparators) {
217-
const thousandSep = this.thousandSeparator === '.' ? '\\.' : this.thousandSeparator;
218-
const regExp = new RegExp(String.raw`${thousandSep}`, 'g');
219-
value = value?.replace(regExp, '');
220-
}
221-
// replacing decimal separator with '.'
222-
if (this.decimalSeparator !== '.') {
223-
const regExp = new RegExp(String.raw`${this.decimalSeparator}`, 'g');
224-
value = value.replace(regExp, '.');
225-
}
226-
handleEvent(actionsApi, 'changeNblur', propName, value);
212+
const oldVal = this.value$ ?? '';
213+
const isValueChanged = event.target.value.toString() !== oldVal.toString();
214+
215+
if (isValueChanged) {
216+
const actionsApi = this.pConn$?.getActionsApi();
217+
const propName = this.pConn$?.getStateProps().value;
218+
let value = event?.target?.value;
219+
// replacing thousand separator with empty string as not required in api call
220+
if (this.configProps$.showGroupSeparators) {
221+
const thousandSep = this.thousandSeparator === '.' ? '\\.' : this.thousandSeparator;
222+
const regExp = new RegExp(String.raw`${thousandSep}`, 'g');
223+
value = value?.replace(regExp, '');
224+
}
225+
// replacing decimal separator with '.'
226+
if (this.decimalSeparator !== '.') {
227+
const regExp = new RegExp(String.raw`${this.decimalSeparator}`, 'g');
228+
value = value.replace(regExp, '.');
229+
}
230+
handleEvent(actionsApi, 'changeNblur', propName, value);
231+
}
227232
}
228233

229234
getErrorMessage() {

packages/angular-sdk-components/src/lib/_components/field/email/email.component.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,26 @@ export class EmailComponent implements OnInit, OnDestroy {
159159
}
160160

161161
fieldOnChange(event: any) {
162-
const value = event?.target?.value;
163-
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
164-
this.pConn$.clearErrorMessages({
165-
property: this.propName
166-
});
162+
const oldVal = this.value$ ?? '';
163+
const isValueChanged = event.target.value.toString() !== oldVal.toString();
164+
165+
if (isValueChanged) {
166+
const value = event?.target?.value;
167+
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
168+
this.pConn$.clearErrorMessages({
169+
property: this.propName
170+
});
171+
}
167172
}
168173

169174
fieldOnBlur(event: any) {
170-
const value = event?.target?.value;
171-
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
175+
const oldVal = this.value$ ?? '';
176+
const isValueChanged = event.target.value.toString() !== oldVal.toString();
177+
178+
if (isValueChanged) {
179+
const value = event?.target?.value;
180+
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
181+
}
172182
}
173183

174184
getErrorMessage() {

packages/angular-sdk-components/src/lib/_components/field/integer/integer.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[required]="bRequired$"
1616
[formControl]="fieldControl"
1717
[attr.data-test-id]="testId"
18-
(change)="fieldOnChange()"
18+
(change)="fieldOnChange($event)"
1919
(blur)="fieldOnBlur($event)"
2020
/>
2121
<mat-error *ngIf="fieldControl.invalid">{{ getErrorMessage() }}</mat-error>

packages/angular-sdk-components/src/lib/_components/field/integer/integer.component.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,25 @@ export class IntegerComponent implements OnInit, OnDestroy {
161161
}
162162
}
163163

164-
fieldOnChange() {
165-
this.pConn$.clearErrorMessages({
166-
property: this.propName
167-
});
164+
fieldOnChange(event: any) {
165+
const oldVal = this.value$ ?? '';
166+
const isValueChanged = event.target.value.toString() !== oldVal.toString();
167+
168+
if (isValueChanged) {
169+
this.pConn$.clearErrorMessages({
170+
property: this.propName
171+
});
172+
}
168173
}
169174

170175
fieldOnBlur(event: any) {
171-
const value = event?.target?.value;
172-
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
176+
const oldVal = this.value$ ?? '';
177+
const isValueChanged = event.target.value.toString() !== oldVal.toString();
178+
179+
if (isValueChanged) {
180+
const value = event?.target?.value;
181+
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
182+
}
173183
}
174184

175185
getErrorMessage() {

packages/angular-sdk-components/src/lib/_components/field/percentage/percentage.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
[required]="bRequired$"
2727
[formControl]="fieldControl"
2828
[attr.data-test-id]="testId"
29-
(change)="fieldOnChange()"
29+
(change)="fieldOnChange($event)"
3030
(blur)="fieldOnBlur($event)"
3131
[readonly]="bReadonly$"
3232
/>

packages/angular-sdk-components/src/lib/_components/field/percentage/percentage.component.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,37 @@ export class PercentageComponent implements OnInit, OnDestroy {
179179
}
180180
}
181181

182-
fieldOnChange() {
183-
this.pConn$.clearErrorMessages({
184-
property: this.propName
185-
});
182+
fieldOnChange(event: any) {
183+
const oldVal = this.value$ ?? '';
184+
const isValueChanged = event.target.value.toString() !== oldVal.toString();
185+
186+
if (isValueChanged) {
187+
this.pConn$.clearErrorMessages({
188+
property: this.propName
189+
});
190+
}
186191
}
187192

188193
fieldOnBlur(event: any) {
189-
let value = event?.target?.value;
190-
value = value ? value.replace(/%/g, '') : '';
191-
// replacing thousand separator with empty string as not required in api call
192-
if (this.configProps$.showGroupSeparators) {
193-
const thousandSep = this.thousandSeparator === '.' ? '\\.' : this.thousandSeparator;
194-
const regExp = new RegExp(String.raw`${thousandSep}`, 'g');
195-
value = value?.replace(regExp, '');
196-
}
197-
// replacing decimal separator with '.'
198-
if (this.decimalSeparator !== '.') {
199-
const regExp = new RegExp(String.raw`${this.decimalSeparator}`, 'g');
200-
value = value.replace(regExp, '.');
194+
const oldVal = this.value$ ?? '';
195+
const isValueChanged = event.target.value.toString() !== oldVal.toString();
196+
197+
if (isValueChanged) {
198+
let value = event?.target?.value;
199+
value = value ? value.replace(/%/g, '') : '';
200+
// replacing thousand separator with empty string as not required in api call
201+
if (this.configProps$.showGroupSeparators) {
202+
const thousandSep = this.thousandSeparator === '.' ? '\\.' : this.thousandSeparator;
203+
const regExp = new RegExp(String.raw`${thousandSep}`, 'g');
204+
value = value?.replace(regExp, '');
205+
}
206+
// replacing decimal separator with '.'
207+
if (this.decimalSeparator !== '.') {
208+
const regExp = new RegExp(String.raw`${this.decimalSeparator}`, 'g');
209+
value = value.replace(regExp, '.');
210+
}
211+
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
201212
}
202-
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
203213
}
204214

205215
getErrorMessage() {

packages/angular-sdk-components/src/lib/_components/field/phone/phone.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[preferredCountries]="['us']"
1212
[enablePlaceholder]="true"
1313
[enableSearch]="true"
14-
(change)="fieldOnChange()"
14+
(change)="fieldOnChange($event)"
1515
(blur)="fieldOnBlur()"
1616
>
1717
</ngx-mat-intl-tel-input>

packages/angular-sdk-components/src/lib/_components/field/phone/phone.component.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ export class PhoneComponent implements OnInit, OnDestroy {
170170
// 'blur' isn't getting fired
171171
}
172172

173-
fieldOnChange() {
174-
if (this.formGroup$.controls[this.controlName$].value) {
175-
const value = this.formGroup$.controls[this.controlName$].value;
173+
fieldOnChange(event: any) {
174+
const oldVal = this.value$ ?? '';
175+
const isValueChanged = event?.target?.value.toString() !== oldVal.toString();
176+
177+
if (isValueChanged) {
178+
const value = event?.target?.value || event?.value || '';
176179
this.afterBlur = true;
177180
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
178181
}

packages/angular-sdk-components/src/lib/_components/field/rich-text/rich-text.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ export class RichTextComponent implements OnInit, OnDestroy {
116116
}
117117
}
118118

119-
fieldOnChange() {
120-
if (this.status === 'error') {
119+
fieldOnChange(editorValue: any) {
120+
const oldVal = this.value$ ?? '';
121+
const newVal = editorValue?.editor?.getBody()?.innerHTML ?? '';
122+
const isValueChanged = newVal.toString() !== oldVal.toString();
123+
124+
if (isValueChanged || this.status === 'error') {
121125
const property = this.propName;
122126
this.pConn$.clearErrorMessages({
123127
property,
@@ -128,6 +132,11 @@ export class RichTextComponent implements OnInit, OnDestroy {
128132
}
129133

130134
fieldOnBlur(editorValue: any) {
131-
handleEvent(this.actionsApi, 'changeNblur', this.propName, editorValue);
135+
const oldVal = this.value$ ?? '';
136+
const isValueChanged = editorValue.toString() !== oldVal.toString();
137+
138+
if (isValueChanged) {
139+
handleEvent(this.actionsApi, 'changeNblur', this.propName, editorValue);
140+
}
132141
}
133142
}

0 commit comments

Comments
 (0)