form-aurora-stefanini 0.1.1 → 0.1.2
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/karma.conf.js +32 -0
- package/ng-package.json +7 -0
- package/package.json +17 -28
- package/src/lib/Components/from-aurora/form-aurora.component.css +117 -0
- package/src/lib/Components/from-aurora/form-aurora.component.html +343 -0
- package/src/lib/Components/from-aurora/form-aurora.component.spec.ts +25 -0
- package/src/lib/Components/from-aurora/form-aurora.component.ts +725 -0
- package/src/lib/Models/company-parameters.ts +16 -0
- package/src/lib/Models/company.ts +25 -0
- package/src/lib/Models/fill.ts +6 -0
- package/src/lib/Models/state.ts +5 -0
- package/src/lib/Models/step.ts +15 -0
- package/src/lib/Models/stepMethod.ts +9 -0
- package/src/lib/form-aurora.module.ts +18 -0
- package/src/lib/services/TemplateService.ts +84 -0
- package/src/lib/services/data.service.ts +83 -0
- package/src/lib/utils/regex.ts +51 -0
- package/src/public-api.ts +9 -0
- package/src/test.ts +21 -0
- package/tsconfig.lib.json +26 -0
- package/tsconfig.spec.json +17 -0
- package/tslint.json +17 -0
- package/bundles/form-aurora-stefanini.umd.js +0 -975
- package/bundles/form-aurora-stefanini.umd.js.map +0 -1
- package/bundles/form-aurora-stefanini.umd.min.js +0 -16
- package/bundles/form-aurora-stefanini.umd.min.js.map +0 -1
- package/esm2015/form-aurora-stefanini.js +0 -5
- package/esm2015/lib/fill.js +0 -3
- package/esm2015/lib/form-aurora.component.js +0 -681
- package/esm2015/lib/form-aurora.module.js +0 -22
- package/esm2015/public-api.js +0 -6
- package/esm5/form-aurora-stefanini.js +0 -5
- package/esm5/lib/fill.js +0 -7
- package/esm5/lib/form-aurora.component.js +0 -733
- package/esm5/lib/form-aurora.module.js +0 -25
- package/esm5/public-api.js +0 -6
- package/fesm2015/form-aurora-stefanini.js +0 -703
- package/fesm2015/form-aurora-stefanini.js.map +0 -1
- package/fesm5/form-aurora-stefanini.js +0 -758
- package/fesm5/form-aurora-stefanini.js.map +0 -1
- package/form-aurora-stefanini.d.ts +0 -4
- package/form-aurora-stefanini.metadata.json +0 -1
- package/lib/fill.d.ts +0 -6
- package/lib/form-aurora.component.d.ts +0 -106
- package/lib/form-aurora.module.d.ts +0 -2
- package/public-api.d.ts +0 -2
@@ -0,0 +1,725 @@
|
|
1
|
+
import {
|
2
|
+
Component,
|
3
|
+
Injectable,
|
4
|
+
Input,
|
5
|
+
ElementRef,
|
6
|
+
OnInit,
|
7
|
+
Renderer2,
|
8
|
+
ViewChild,
|
9
|
+
OnChanges,
|
10
|
+
SimpleChanges,
|
11
|
+
Output,
|
12
|
+
EventEmitter
|
13
|
+
} from '@angular/core';
|
14
|
+
import {FormGroup, FormControl, NgForm, Form, Validators} from '@angular/forms';
|
15
|
+
import {HttpClient} from '@angular/common/http';
|
16
|
+
|
17
|
+
// import moment from 'moment';
|
18
|
+
import {NgbDateAdapter, NgbDateParserFormatter, NgbDateStruct, NgbDatepickerI18n} from '@ng-bootstrap/ng-bootstrap';
|
19
|
+
import * as moment_ from 'moment';
|
20
|
+
import { Fill } from '../../Models/fill';
|
21
|
+
import { regexType } from '../../utils/regex';
|
22
|
+
import { Company } from '../../Models/company';
|
23
|
+
import { Step } from '../../Models/step';
|
24
|
+
import { CommonDataService } from '../../services/data.service';
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
const moment = moment_;
|
31
|
+
// import { regexType } from "@app/_shared/_util/regex";
|
32
|
+
// import { ExternalService } from '@app/_shared/_services/external.service';
|
33
|
+
// import { AuroraService } from '@app/_shared/_services/aurora.service';
|
34
|
+
|
35
|
+
/**
|
36
|
+
* This Service handles how the date is represented in scripts i.e. ngModel.
|
37
|
+
*/
|
38
|
+
@Injectable()
|
39
|
+
export class CustomAdapter extends NgbDateAdapter<string> {
|
40
|
+
|
41
|
+
readonly DELIMITER = '/';
|
42
|
+
|
43
|
+
fromModel(value: string | null): NgbDateStruct | null {
|
44
|
+
if (value) {
|
45
|
+
const date = value.split(this.DELIMITER);
|
46
|
+
return {
|
47
|
+
day: parseInt(date[0], 10),
|
48
|
+
month: parseInt(date[1], 10),
|
49
|
+
year: parseInt(date[2], 10)
|
50
|
+
};
|
51
|
+
}
|
52
|
+
return null;
|
53
|
+
}
|
54
|
+
|
55
|
+
toModel(date: NgbDateStruct | null): string | null {
|
56
|
+
//return date ? date.day + this.DELIMITER + date.month + this.DELIMITER + date.year : null;
|
57
|
+
return date ? (date.day < 10 ? 0 + date.day : date.day) + this.DELIMITER + (date.month < 10 ? 0 + date.month : date.month) + this.DELIMITER + date.year : '';
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* This Service handles how the date is rendered and parsed from keyboard i.e. in the bound input field.
|
63
|
+
*/
|
64
|
+
@Injectable()
|
65
|
+
export class CustomDateParserFormatter extends NgbDateParserFormatter {
|
66
|
+
|
67
|
+
readonly DELIMITER = '/';
|
68
|
+
|
69
|
+
parse(value: string): NgbDateStruct | null {
|
70
|
+
if (value) {
|
71
|
+
const date = value.split(this.DELIMITER);
|
72
|
+
return {
|
73
|
+
day: parseInt(date[0], 10),
|
74
|
+
month: parseInt(date[1], 10),
|
75
|
+
year: parseInt(date[2], 10)
|
76
|
+
};
|
77
|
+
}
|
78
|
+
return null;
|
79
|
+
}
|
80
|
+
|
81
|
+
format(date: NgbDateStruct | null): string {
|
82
|
+
return date ? (date.day < 10 ? '0' + date.day : date.day) + this.DELIMITER + (date.month < 10 ? '0' + date.month : date.month) + this.DELIMITER + date.year : '';
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
const I18N_VALUES = {
|
87
|
+
'es': {
|
88
|
+
weekdays: ['Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa', 'Do'],
|
89
|
+
months: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
|
90
|
+
weekLabel: 'sem'
|
91
|
+
}
|
92
|
+
// other languages you would support
|
93
|
+
};
|
94
|
+
|
95
|
+
@Injectable()
|
96
|
+
export class I18n {
|
97
|
+
language = 'es';
|
98
|
+
}
|
99
|
+
|
100
|
+
// Define custom service providing the months and weekdays translations
|
101
|
+
@Injectable()
|
102
|
+
export class CustomDatepickerI18n extends NgbDatepickerI18n {
|
103
|
+
constructor(private _i18n: I18n) {
|
104
|
+
super();
|
105
|
+
}
|
106
|
+
|
107
|
+
getWeekdayLabel(weekday: number): string {
|
108
|
+
return I18N_VALUES[this._i18n.language].weekdays[weekday - 1];
|
109
|
+
}
|
110
|
+
|
111
|
+
getWeekLabel(): string {
|
112
|
+
return I18N_VALUES[this._i18n.language].weekLabel;
|
113
|
+
}
|
114
|
+
|
115
|
+
getMonthShortName(month: number): string {
|
116
|
+
return I18N_VALUES[this._i18n.language].months[month - 1];
|
117
|
+
}
|
118
|
+
|
119
|
+
getMonthFullName(month: number): string {
|
120
|
+
return this.getMonthShortName(month);
|
121
|
+
}
|
122
|
+
|
123
|
+
getDayAriaLabel(date: NgbDateStruct): string {
|
124
|
+
return `${date.day}-${date.month}-${date.year}`;
|
125
|
+
}
|
126
|
+
|
127
|
+
getWeekdayShortName(weekday: number): string {
|
128
|
+
return I18N_VALUES[this._i18n.language].weekdays[weekday - 1];
|
129
|
+
};
|
130
|
+
}
|
131
|
+
|
132
|
+
|
133
|
+
@Component({
|
134
|
+
selector: 'lib-FormAurora',
|
135
|
+
templateUrl: './form-aurora.component.html',
|
136
|
+
styleUrls: ['./form-aurora.component.css'],
|
137
|
+
providers: [
|
138
|
+
{provide: NgbDateAdapter, useClass: CustomAdapter},
|
139
|
+
{provide: NgbDateParserFormatter, useClass: CustomDateParserFormatter},
|
140
|
+
{provide: NgbDatepickerI18n, useClass: CustomDatepickerI18n},
|
141
|
+
I18n
|
142
|
+
]
|
143
|
+
})
|
144
|
+
export class FormAuroraComponent implements OnInit, OnChanges {
|
145
|
+
|
146
|
+
@Input() dataClassCss: any;
|
147
|
+
@Input() dataForm: any;
|
148
|
+
@Input() clickSubmit: any;
|
149
|
+
@Input() dataReloadForm: any;
|
150
|
+
@Input() welcomeTitle: any;
|
151
|
+
@Input() welcomeDescription: any;
|
152
|
+
@Input() urlPdf: string;
|
153
|
+
@Input() nameCompany: string;
|
154
|
+
@Input() schedule: string;
|
155
|
+
@Input() isSimpleFlow: boolean;
|
156
|
+
@Input() company: Company;
|
157
|
+
@Input() steps: Step[];
|
158
|
+
@ViewChild('formDynamic', { static: true }) formDynamic: NgForm;
|
159
|
+
@Output() response = new EventEmitter<any>();
|
160
|
+
@Output() summit = new EventEmitter<any>();
|
161
|
+
@Output() viewAuthData = new EventEmitter<any>();
|
162
|
+
|
163
|
+
tipodocNumDoc: boolean = false;
|
164
|
+
onSubmitEvent: any = false;
|
165
|
+
countSubmit = 0;
|
166
|
+
watchValid = false;
|
167
|
+
watchRequired = false;
|
168
|
+
captchaValid: boolean = false;
|
169
|
+
displayMonths = 2;
|
170
|
+
navigation = 'select';
|
171
|
+
showWeekNumbers = false;
|
172
|
+
outsideDays = 'visible';
|
173
|
+
respServiceSegmentation: any = null;
|
174
|
+
base64CheckAuthData : any = undefined;
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
//emailPattern = "^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$";
|
180
|
+
|
181
|
+
today = moment(new Date());
|
182
|
+
maxYear = this.today.year();
|
183
|
+
minYear = this.today.year() - 82;
|
184
|
+
minDate = this.minYear.toString() + '-' + this.today.month().toString().padStart(2, '0') + '-' + this.today.date().toString().padStart(2, '0');// {year: this.minYear, month: this.today.month(), day: this.today.date()};
|
185
|
+
maxDate = this.maxYear.toString() + '-' + (this.today.month() + 1).toString().padStart(2, '0') + '-' + this.today.date().toString().padStart(2, '0');// {year: this.maxYear, month: this.today.month() + 1, day: this.today.date()};
|
186
|
+
|
187
|
+
//Revisar variables
|
188
|
+
recharge: boolean = false;
|
189
|
+
indicativo: string = "57";
|
190
|
+
@ViewChild("modalTurns", { static: false }) myModal: ElementRef;
|
191
|
+
filldata: Fill;
|
192
|
+
defaultDocType: string = "Cédula de ciudadanía";
|
193
|
+
|
194
|
+
patternNotValidDcto: boolean = false;
|
195
|
+
patternNotValidCel: boolean = false;
|
196
|
+
|
197
|
+
constructor(private data: CommonDataService, private http: HttpClient) { }
|
198
|
+
|
199
|
+
ngOnInit(): void {
|
200
|
+
this.minDate = new Date(this.minDate).toISOString().split('T')[0]
|
201
|
+
setTimeout(() => {
|
202
|
+
this.startComponent();
|
203
|
+
}, 2000);
|
204
|
+
}
|
205
|
+
|
206
|
+
|
207
|
+
startComponent() {
|
208
|
+
//ordena los campos
|
209
|
+
if (this.dataForm != null && this.dataForm.formQuestions != undefined) {
|
210
|
+
//Same row fields
|
211
|
+
this.tipodocNumDoc = (this.dataForm.formQuestions.some(question => question.question.value === "tipoDoc") && this.dataForm.formQuestions.some(question => question.question.value === "numeroDoc")) ? true : false;
|
212
|
+
|
213
|
+
this.dataForm.formQuestions = this.dataForm.formQuestions.sort(function (a, b) {
|
214
|
+
return a.order - b.order;
|
215
|
+
});
|
216
|
+
let existcaptcha = this.dataForm.formQuestions.filter((item) => item.question.questionType.id == 6);
|
217
|
+
|
218
|
+
if (existcaptcha.length == 0) {
|
219
|
+
this.captchaValid = true;
|
220
|
+
}
|
221
|
+
|
222
|
+
for (const item of this.dataForm.formQuestions) {
|
223
|
+
if (item.question.maxlength == null || item.question.maxlength == undefined || item.question.maxlength == 0) {
|
224
|
+
item.question.maxlength = 524288; //defaultvalue
|
225
|
+
}
|
226
|
+
|
227
|
+
if (item.question.minLength == null || item.question.minLength == undefined) {
|
228
|
+
item.question.minLength = 0;
|
229
|
+
}
|
230
|
+
|
231
|
+
this.dataReloadForm.forEach(element => {
|
232
|
+
this.filldata = element;
|
233
|
+
|
234
|
+
if ((item.question.questionType.id === 2 || item.question.questionType.id === 1 ||
|
235
|
+
item.question.questionType.id === 3) && (this.filldata.data !== null &&
|
236
|
+
this.filldata.data !== undefined) && item.question.id === this.filldata.id) {
|
237
|
+
item.question.registred = this.filldata.data;
|
238
|
+
}
|
239
|
+
});
|
240
|
+
|
241
|
+
if (item.question.registred == null || item.question.minLength == undefined) {
|
242
|
+
item.question.registred = '';
|
243
|
+
}
|
244
|
+
}
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
range = new FormGroup({
|
249
|
+
start: new FormControl(),
|
250
|
+
end: new FormControl(),
|
251
|
+
});
|
252
|
+
|
253
|
+
resolvedCaptcha(captchaResponse: string) {
|
254
|
+
this.captchaValid = true
|
255
|
+
if (!this.formDynamic.form.value.captcha) {
|
256
|
+
this.formDynamic.controls.captcha.setValue(captchaResponse)
|
257
|
+
this.formDynamic.form.value.captcha = captchaResponse
|
258
|
+
document.getElementById("btnIng").style.opacity = !this.formDynamic.valid ? "0.65" : "1";
|
259
|
+
}
|
260
|
+
}
|
261
|
+
|
262
|
+
//Forms
|
263
|
+
//Metodo para evitar el render de los items del for
|
264
|
+
public trackByIndex(index: number, obj: any): any {
|
265
|
+
return index;
|
266
|
+
}
|
267
|
+
|
268
|
+
onChangeValidPatter(event, question) {
|
269
|
+
if (question.pattern != undefined) {
|
270
|
+
let valid = true;
|
271
|
+
let keyvalid = [8, 32, 37, 38, 39, 40, 46, 9];
|
272
|
+
//diferente de Backpsace
|
273
|
+
//se deja catch por error no controlable en otro tiempo de ejecucion
|
274
|
+
try {
|
275
|
+
if (!keyvalid.includes(event.keyCode)) {
|
276
|
+
const regex = new RegExp(question.pattern);
|
277
|
+
valid = regex.test(event.key);
|
278
|
+
}
|
279
|
+
} catch (error) { }
|
280
|
+
|
281
|
+
return valid;
|
282
|
+
}
|
283
|
+
if (question.questionType !== undefined) {
|
284
|
+
if (question.questionType.description === 'Number') {
|
285
|
+
if (question.value === 'numeroDoc') {
|
286
|
+
this.validateNumeroDocumento(this.formDynamic.controls["numeroDoc"].value.toString());
|
287
|
+
}else if (question.value === 'celular'){
|
288
|
+
this.validateCelular(this.formDynamic.controls["celular"].value.toString());
|
289
|
+
}
|
290
|
+
|
291
|
+
}
|
292
|
+
}
|
293
|
+
document.getElementById("char" + question.value).setAttribute("hidden", "true");
|
294
|
+
|
295
|
+
//if temporal mientras se migran todos los tipos de campos al foreach
|
296
|
+
if (question.questionType.id != 11 && question.questionType.id != 7) {
|
297
|
+
if (this.validMinLength(this.formDynamic, question)) {
|
298
|
+
document.getElementById(question.value).style.borderColor = "#FF0000";
|
299
|
+
document.getElementById("ml" + question.value).removeAttribute("hidden");
|
300
|
+
}
|
301
|
+
else {
|
302
|
+
document.getElementById(question.value).style.borderColor = "#E4E4E4";
|
303
|
+
document.getElementById("ml" + question.value).setAttribute("hidden", "true");
|
304
|
+
}
|
305
|
+
if (this.validMaxLength(this.formDynamic, question)) {
|
306
|
+
document.getElementById(question.value).style.borderColor = "#FF0000";
|
307
|
+
document.getElementById("mxl" + question.value).removeAttribute("hidden");
|
308
|
+
}
|
309
|
+
else {
|
310
|
+
document.getElementById(question.value).style.borderColor = "#E4E4E4";
|
311
|
+
document.getElementById("mxl" + question.value).setAttribute("hidden", "true");
|
312
|
+
}
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
this.dataForm.formQuestions.forEach(formQuestion => {
|
317
|
+
switch (formQuestion.question.questionType.id) {
|
318
|
+
//se valida campo de tipo calendario
|
319
|
+
case 7:
|
320
|
+
if (question.questionType.id == 7)
|
321
|
+
this.calendarRulesValidate(formQuestion);
|
322
|
+
break;
|
323
|
+
//se valida campo de tipo email
|
324
|
+
case 11:
|
325
|
+
if (question.questionType.id == 11)
|
326
|
+
this.emailRulesValidate(formQuestion);
|
327
|
+
break;
|
328
|
+
}
|
329
|
+
});
|
330
|
+
|
331
|
+
document.getElementById("btnIng").style.opacity = !this.formDynamic.valid ? "0.65" : "1";
|
332
|
+
}
|
333
|
+
|
334
|
+
validOnlyText(event) {
|
335
|
+
let regex = /^[a-zA-Z\u00C0-\u017F]+$/g;
|
336
|
+
if (event.charCode == 32) {
|
337
|
+
return true;
|
338
|
+
}
|
339
|
+
let valid = regex.test(event.key);
|
340
|
+
|
341
|
+
return valid;
|
342
|
+
}
|
343
|
+
|
344
|
+
validDate(event) {
|
345
|
+
/*let pattern = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20)[0-9]{2}/;
|
346
|
+
const regex = new RegExp(pattern);
|
347
|
+
valid = regex.test(event.key);
|
348
|
+
*/
|
349
|
+
const matches = String(event.key).match(regexType.date.exp);
|
350
|
+
let valid = true
|
351
|
+
if (matches === null)
|
352
|
+
valid = false;
|
353
|
+
|
354
|
+
// alert(valid);
|
355
|
+
|
356
|
+
return valid;
|
357
|
+
|
358
|
+
}
|
359
|
+
|
360
|
+
onChangeValidDate(event) {
|
361
|
+
|
362
|
+
//let pattern = /(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12][0-9]|3[01])\/(?:19|20)[0-9]{2}/;
|
363
|
+
let dateN = /[0-9]|\//
|
364
|
+
let valid = true
|
365
|
+
const regex = new RegExp(dateN);
|
366
|
+
valid = regex.test(event.key);
|
367
|
+
return valid;
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
rediretoutside(event, question) {
|
372
|
+
//se deja catch por error no controlable en otro tiempo de ejecucion
|
373
|
+
try {
|
374
|
+
event.preventDefault();
|
375
|
+
window.open(question.value, "_blank");
|
376
|
+
} catch (error) { }
|
377
|
+
}
|
378
|
+
|
379
|
+
/**
|
380
|
+
* Dispatch submit event for validations exists
|
381
|
+
* @param change
|
382
|
+
*/
|
383
|
+
ngOnChanges(change: SimpleChanges) {
|
384
|
+
this.countSubmit++
|
385
|
+
}
|
386
|
+
//onSubmit(form: NgForm) {
|
387
|
+
onSubmit() {
|
388
|
+
let form = this.formDynamic;
|
389
|
+
this.watchValid = true;
|
390
|
+
this.watchRequired = true;
|
391
|
+
|
392
|
+
if (form.valid) {
|
393
|
+
if (!this.validRulesFields(form.controls["numeroDoc"].value.toString(), form.controls["celular"].value.toString(), form.controls["email"].value))
|
394
|
+
return false;
|
395
|
+
}
|
396
|
+
|
397
|
+
if (this.validMinlenghtAllQuestions(form.value) && this.validMaxLengthAllQuestions(form.value) && form.valid) {
|
398
|
+
if (this.dataForm.urlSend != "" && this.captchaValid) {
|
399
|
+
this.http.post<any>(this.dataForm.urlSend, form.value).subscribe((resp) => this.response.emit(resp));
|
400
|
+
} else if (form.valid && this.captchaValid) {
|
401
|
+
this.summit.emit(form.value);
|
402
|
+
}
|
403
|
+
}
|
404
|
+
}
|
405
|
+
|
406
|
+
private findParamBoolean(params: any, idParam: number) {
|
407
|
+
let showDescriptionParam = params.find((x) => x.id == idParam);
|
408
|
+
return showDescriptionParam != null && showDescriptionParam.value == "true";
|
409
|
+
}
|
410
|
+
|
411
|
+
validRulesFields(numeroDoc: String, numeroCel: String, email: String): boolean {
|
412
|
+
// Validaciones para celular en caso de indicativo en Colombia
|
413
|
+
let cel = document.getElementById("charcelular");
|
414
|
+
let doc = document.getElementById("charnumeroDoc");
|
415
|
+
let valOk = true;
|
416
|
+
if (this.indicativo == "+57" || this.indicativo == "57") {
|
417
|
+
let stringOrdenado = this.orderString(numeroDoc);
|
418
|
+
if (this.nameCompany.toUpperCase() !== 'CLARO') {//claro acepta nro consecutivos
|
419
|
+
if (numeroDoc == stringOrdenado) {
|
420
|
+
doc.style.borderColor = "#FF0000";
|
421
|
+
doc.removeAttribute("hidden");
|
422
|
+
doc.textContent = "El numero documento No debe contener caracteres consecutivos";
|
423
|
+
valOk = false;
|
424
|
+
|
425
|
+
//this.msgErrorCampo = "El numero documento No debe contener caracteres consecutivos";
|
426
|
+
//return false;
|
427
|
+
}
|
428
|
+
}
|
429
|
+
if (numeroCel.substring(0, 1) != "3") {
|
430
|
+
cel.style.borderColor = "#FF0000";
|
431
|
+
cel.removeAttribute("hidden");
|
432
|
+
cel.textContent = "El primer carácter del celular debe ser 3";
|
433
|
+
valOk = false;
|
434
|
+
|
435
|
+
//this.msgErrorCampo = "El primer carácter del celular debe ser 3";
|
436
|
+
//return false;
|
437
|
+
}
|
438
|
+
/*
|
439
|
+
if (parseInt(numeroCel.substring(0, 3)) > 350) {
|
440
|
+
cel.style.borderColor = "#FF0000";
|
441
|
+
cel.removeAttribute("hidden");
|
442
|
+
cel.textContent = "El prefijo del celular no debe ser mayor a 350";
|
443
|
+
valOk = false;
|
444
|
+
//this.msgErrorCampo = "El prefijo del celular no debe ser mayor a 350";
|
445
|
+
//return false;
|
446
|
+
}
|
447
|
+
*/
|
448
|
+
//En caso de que el número se repita, ejemplo 33333333
|
449
|
+
let listnumber = numeroDoc.substring(0, 1);
|
450
|
+
for (let index = 1; index < numeroDoc.length; index++) {
|
451
|
+
listnumber = listnumber + numeroDoc.substring(0, 1);
|
452
|
+
}
|
453
|
+
|
454
|
+
if (numeroDoc == listnumber) {
|
455
|
+
doc.style.borderColor = "#FF0000";
|
456
|
+
doc.removeAttribute("hidden");
|
457
|
+
doc.textContent = "Caracteres numéricos no se pueden repetirse de manera continua ";
|
458
|
+
valOk = false;
|
459
|
+
|
460
|
+
//this.msgErrorCampo = "Caracteres numéricos no se pueden repetirse de manera continua ";
|
461
|
+
//return false;
|
462
|
+
}
|
463
|
+
if (!this.validateNumeroDocumento(numeroDoc)) {
|
464
|
+
return false;
|
465
|
+
}
|
466
|
+
if (!this.validateCelular(numeroCel)) {
|
467
|
+
return false;
|
468
|
+
}
|
469
|
+
|
470
|
+
|
471
|
+
// En caso de que el número se repita, ejemplo 33333333
|
472
|
+
let arrayPhoneRepeat = Array.from(String(numeroCel), Number);
|
473
|
+
let arrayPhoneOutRepeat = [...new Set(arrayPhoneRepeat)];
|
474
|
+
if (arrayPhoneOutRepeat.length == 1) {
|
475
|
+
cel.style.borderColor = "#FF0000";
|
476
|
+
cel.removeAttribute("hidden");
|
477
|
+
cel.textContent = "El número que ingresa no es valido";
|
478
|
+
valOk = false;
|
479
|
+
//this.msgErrorCampo = "El número que ingresa no es valido";
|
480
|
+
//return false;
|
481
|
+
}
|
482
|
+
} else if (this.indicativo == "+593" || this.indicativo == "593") {
|
483
|
+
if (numeroCel.substring(0, 1) != "9") {
|
484
|
+
cel.style.borderColor = "#FF0000";
|
485
|
+
cel.removeAttribute("hidden");
|
486
|
+
cel.textContent = "El primer carácter del celular debe ser 9";
|
487
|
+
valOk = false;
|
488
|
+
//this.msgErrorCampo = "El primer carácter del celular debe ser 9";
|
489
|
+
//return false;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
//se validan los campos por tipo de campo y no por value
|
493
|
+
this.dataForm.formQuestions.forEach(formQuestion => {
|
494
|
+
switch (formQuestion.question.questionType.id) {
|
495
|
+
//se valida campo de tipo email
|
496
|
+
case 11:
|
497
|
+
valOk = this.emailRulesValidate(formQuestion);
|
498
|
+
break;
|
499
|
+
}
|
500
|
+
});
|
501
|
+
|
502
|
+
return valOk;
|
503
|
+
}
|
504
|
+
|
505
|
+
orderString(value: String) {
|
506
|
+
let arrayNumber = [];
|
507
|
+
for (let index = 0; index < value.length; index++) {
|
508
|
+
arrayNumber.push(parseInt(value.substring(index, index + 1)));
|
509
|
+
}
|
510
|
+
//ordena el array
|
511
|
+
arrayNumber.sort(function (a, b) {
|
512
|
+
return a - b;
|
513
|
+
});
|
514
|
+
let numberOrder = "";
|
515
|
+
numberOrder = arrayNumber[0];
|
516
|
+
for (let index = 1; index < arrayNumber.length; index++) {
|
517
|
+
numberOrder = numberOrder + (arrayNumber[0] + index).toString();
|
518
|
+
}
|
519
|
+
return numberOrder;
|
520
|
+
}
|
521
|
+
|
522
|
+
validMinlenghtAllQuestions(form: any): boolean {
|
523
|
+
for (const item of this.dataForm.formQuestions) {
|
524
|
+
if (item.question.questionType.id == 1 || item.question.questionType.id == 2) {
|
525
|
+
let minLength = parseInt(item.question.minLength);
|
526
|
+
let formValueLength = parseInt(form[item.question.value].toString().length);
|
527
|
+
if (minLength > 0 && formValueLength != minLength && formValueLength < minLength) return false;
|
528
|
+
}
|
529
|
+
}
|
530
|
+
return true;
|
531
|
+
}
|
532
|
+
|
533
|
+
validMaxLengthAllQuestions(form: any): boolean {
|
534
|
+
for (const item of this.dataForm.formQuestions) {
|
535
|
+
if (item.question.questionType.id == 1 || item.question.questionType.id == 2) {
|
536
|
+
let maxLength = parseInt(item.question.maxLength);
|
537
|
+
let formValueLength = parseInt(form[item.question.value].toString().length);
|
538
|
+
if (maxLength > 0 && formValueLength != maxLength && formValueLength > maxLength) return false;
|
539
|
+
}
|
540
|
+
}
|
541
|
+
return true;
|
542
|
+
}
|
543
|
+
|
544
|
+
validRequired(form: NgForm, question): Boolean {
|
545
|
+
//se deja catch por error no controlable en otro tiempo de ejecucion
|
546
|
+
try {
|
547
|
+
if (question != undefined && question.value != undefined) {
|
548
|
+
if (
|
549
|
+
form.controls[question.value] != undefined &&
|
550
|
+
form.controls[question.value].errors != null &&
|
551
|
+
form.controls[question.value].errors.required
|
552
|
+
) {
|
553
|
+
return true;
|
554
|
+
}
|
555
|
+
}
|
556
|
+
} catch (error) { }
|
557
|
+
return false;
|
558
|
+
}
|
559
|
+
|
560
|
+
validMinLength(form: NgForm, question): Boolean {
|
561
|
+
//se deja catch por error no controlable en otro tiempo de ejecucion
|
562
|
+
try {
|
563
|
+
if (question != undefined && question.value != undefined) {
|
564
|
+
if (question.minLength > form.controls[question.value].value.toLocaleString().length && question.minLength > 0) {
|
565
|
+
return true;
|
566
|
+
}
|
567
|
+
}
|
568
|
+
} catch (error) { }
|
569
|
+
return false;
|
570
|
+
}
|
571
|
+
|
572
|
+
validMaxLength(form: NgForm, question): Boolean {
|
573
|
+
//se deja catch por error no controlable en otro tiempo de ejecucion
|
574
|
+
try {
|
575
|
+
if (question != undefined && question.value != undefined) {
|
576
|
+
if (question.maxLength > 0) {
|
577
|
+
if (question.maxLength + 1 <= form.controls[question.value].value.toString().replace(/\./g, '').length) {
|
578
|
+
if (!this.formDynamic.controls[question.value].hasError('errorMaxLength')) {
|
579
|
+
this.formDynamic.controls[question.value].setErrors({ 'errorMaxLength': true })
|
580
|
+
}
|
581
|
+
return true;
|
582
|
+
}
|
583
|
+
}
|
584
|
+
}
|
585
|
+
} catch (error) { }
|
586
|
+
return false;
|
587
|
+
}
|
588
|
+
|
589
|
+
tycSelection(event) {
|
590
|
+
this.viewAuthData.emit(event);
|
591
|
+
}
|
592
|
+
|
593
|
+
openLabelUrl(event, question) {
|
594
|
+
event.preventDefault()
|
595
|
+
let tyc = <HTMLInputElement>document.getElementById("check" + question.id);
|
596
|
+
tyc.style.color = "#A3AD32";
|
597
|
+
window.open(question.urllabel, "_blank");
|
598
|
+
}
|
599
|
+
|
600
|
+
cancellKeypress() {
|
601
|
+
return false;
|
602
|
+
}
|
603
|
+
emailRulesValidate(formQuestion) {
|
604
|
+
let valOk = true;
|
605
|
+
try {
|
606
|
+
let hasError = false;
|
607
|
+
document.getElementById(formQuestion.question.id).setAttribute("hidden", "true");
|
608
|
+
let eml = document.getElementById(formQuestion.question.id);
|
609
|
+
let email = formQuestion.question.registred;
|
610
|
+
if (!hasError) {
|
611
|
+
if (formQuestion.question.required && (email == "" || email == undefined || email == null)) {
|
612
|
+
eml.style.borderColor = "#FF0000";
|
613
|
+
eml.textContent = "El correco eléctronico es requerido";
|
614
|
+
eml.removeAttribute("hidden");
|
615
|
+
valOk = false;
|
616
|
+
hasError = true;
|
617
|
+
}
|
618
|
+
}
|
619
|
+
if (!hasError) {
|
620
|
+
if (this.validMinLength(undefined, formQuestion.question)) {
|
621
|
+
eml.style.borderColor = "#FF0000";
|
622
|
+
eml.textContent = "Debe ser mínimo de " + formQuestion.question.minLength + " caracteres";
|
623
|
+
document.getElementById(formQuestion.question.id).removeAttribute("hidden");
|
624
|
+
valOk = false;
|
625
|
+
hasError = true;
|
626
|
+
}
|
627
|
+
}
|
628
|
+
if (!hasError) {
|
629
|
+
if (this.validMaxLength(undefined, formQuestion.question)) {
|
630
|
+
eml.style.borderColor = "#FF0000";
|
631
|
+
eml.textContent = "Debe ser maximo de " + formQuestion.question.maxLength + " caracteres";
|
632
|
+
document.getElementById(formQuestion.question.id).removeAttribute("hidden");
|
633
|
+
valOk = false;
|
634
|
+
hasError = true;
|
635
|
+
}
|
636
|
+
}
|
637
|
+
if (!hasError) {
|
638
|
+
|
639
|
+
const matches = String(email).match(regexType.email.exp);
|
640
|
+
if (matches == null) {
|
641
|
+
eml.style.borderColor = "#FF0000";
|
642
|
+
eml.textContent = "Tu email es invalido";
|
643
|
+
eml.removeAttribute("hidden");
|
644
|
+
valOk = false;
|
645
|
+
hasError = true;
|
646
|
+
}
|
647
|
+
}
|
648
|
+
|
649
|
+
} catch (error) {
|
650
|
+
|
651
|
+
}
|
652
|
+
return valOk;
|
653
|
+
}
|
654
|
+
|
655
|
+
calendarRulesValidate(formQuestion) {
|
656
|
+
let hasError = false;
|
657
|
+
try {
|
658
|
+
document.getElementById(formQuestion.question.id).setAttribute("hidden", "true");
|
659
|
+
let ecalendar = document.getElementById(formQuestion.question.id);
|
660
|
+
//se valida que no sea null si es requerido
|
661
|
+
let date = formQuestion.question.registred;
|
662
|
+
if (formQuestion.question.required && (date == "" || date == undefined || date == null)) {
|
663
|
+
ecalendar.style.borderColor = "#FF0000";
|
664
|
+
ecalendar.textContent = "La fecha es requerida";
|
665
|
+
ecalendar.removeAttribute("hidden");
|
666
|
+
}
|
667
|
+
} catch (error) {
|
668
|
+
|
669
|
+
}
|
670
|
+
}
|
671
|
+
|
672
|
+
validateNotSpace(event) {
|
673
|
+
if (event.charCode == 32) {
|
674
|
+
return false;
|
675
|
+
} else {
|
676
|
+
return true;
|
677
|
+
}
|
678
|
+
}
|
679
|
+
validateNumeroDocumento(numeroDoc: String) {
|
680
|
+
if (!numeroDoc.match("^[0-9]*$")) {
|
681
|
+
this.formDynamic.controls["numeroDoc"].setValidators([Validators.pattern('^[0-9]*$')]);
|
682
|
+
this.formDynamic.controls["numeroDoc"].markAsDirty();
|
683
|
+
this.formDynamic.controls["numeroDoc"].updateValueAndValidity();
|
684
|
+
this.formDynamic.controls["numeroDoc"].markAsTouched();
|
685
|
+
this.patternNotValidDcto = true;
|
686
|
+
return false;
|
687
|
+
}
|
688
|
+
this.patternNotValidDcto = false;
|
689
|
+
return true;
|
690
|
+
}
|
691
|
+
validateCelular(numeroCel: String) {
|
692
|
+
if (!numeroCel.match("^[0-9]*$")) {
|
693
|
+
this.formDynamic.controls["celular"].setValidators([Validators.pattern('^[0-9]*$')]);
|
694
|
+
this.formDynamic.controls["celular"].markAsDirty();
|
695
|
+
this.formDynamic.controls["celular"].updateValueAndValidity();
|
696
|
+
this.formDynamic.controls["celular"].markAsTouched();
|
697
|
+
this.patternNotValidCel = true;
|
698
|
+
return false;
|
699
|
+
}
|
700
|
+
this.patternNotValidCel = false;
|
701
|
+
return true;
|
702
|
+
}
|
703
|
+
|
704
|
+
onkeypress(event)
|
705
|
+
{
|
706
|
+
return (event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57
|
707
|
+
}
|
708
|
+
|
709
|
+
onChangeStep(step: Step, nextStep: Step, value) {
|
710
|
+
if (nextStep && nextStep.stepOrder != 1) {
|
711
|
+
this.resetField(step);
|
712
|
+
nextStep.viewData = [];
|
713
|
+
nextStep.viewData = nextStep.stepData.filter(x => x.relationalIds.includes(Number(value)));
|
714
|
+
|
715
|
+
}
|
716
|
+
}
|
717
|
+
resetField(stepIn : Step) {
|
718
|
+
this.steps.forEach(step => {
|
719
|
+
if (step.stepOrder > stepIn.stepOrder) {
|
720
|
+
step.viewData = undefined;
|
721
|
+
step.value = undefined;
|
722
|
+
}
|
723
|
+
});
|
724
|
+
}
|
725
|
+
}
|