fixed regex for float and integer fields
This commit is contained in:
parent
8518810d34
commit
d10e8ef3b5
|
@ -102,7 +102,7 @@
|
|||
</mat-form-field>
|
||||
<mat-form-field *ngIf="x.get('tipo')?.value === 'number'">
|
||||
<mat-label for="val">value</mat-label>
|
||||
<input matInput formControlName="val" type="number"/>
|
||||
<input matInput formControlName="val" type="text"/>
|
||||
<mat-error>{{checkForErrorsIn(facetTemplate.key,ind,i,'number')}}</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field *ngIf="x.get('tipo')?.value === 'complexType'">
|
||||
|
|
|
@ -189,13 +189,17 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
|
|||
valFc.setValue('');
|
||||
valFc.setValidators([Validators.required]);
|
||||
}
|
||||
if(newValue==='password'||newValue==='text'||newValue==='number'){
|
||||
if(newValue==='password'||newValue==='text'){
|
||||
valFc.setValue('');
|
||||
valFc.setValidators([Validators.required]);
|
||||
}
|
||||
if(newValue==='number'){
|
||||
valFc.setValue('');
|
||||
valFc.setValidators([Validators.required,Validators.pattern('^[-+]?[0-9]+$')]);
|
||||
}
|
||||
if(newValue==='float'){
|
||||
valFc.setValue('');
|
||||
valFc.setValidators([Validators.required,Validators.pattern('^[-+]?[0-9]+\.[0-9]+$')]);
|
||||
valFc.setValidators([Validators.required,Validators.pattern('^[-+]?[0-9]*\.?[0-9]+$')]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,31 +233,44 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
|
|||
checkForErrors(valFc:AbstractControl, inputType:string): string{
|
||||
let errorMsg: string;
|
||||
errorMsg='';
|
||||
|
||||
if(valFc.hasError('required')){
|
||||
if(inputType==='number' && valFc.hasError('required')){
|
||||
errorMsg = 'Input field is not an integer';
|
||||
return errorMsg;
|
||||
}
|
||||
if(inputType!=='number' && valFc.hasError('required')){
|
||||
errorMsg ='The field must not be empty';
|
||||
return errorMsg;
|
||||
}
|
||||
if(!this.checkIfEmpty(valFc.value)&& inputType==='datetime'){
|
||||
if(!this.isIsoDate(valFc.value)){
|
||||
errorMsg = 'Date is not in correct ISO format';
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
}else if(!this.checkIfEmpty(valFc.value)&& inputType==='complexType'){
|
||||
if(!this.isJsonString(valFc.value)){
|
||||
errorMsg = 'Please insert a valid JSON string';
|
||||
return errorMsg;
|
||||
}
|
||||
}else
|
||||
{
|
||||
if(valFc.hasError('pattern')){
|
||||
errorMsg = ''+ valFc.value+'is not a correct value';
|
||||
if(!this.checkIfEmpty(valFc.value)&& inputType==='number'){
|
||||
console.debug('++++++++ NAN - IS NUMBER +++++++');
|
||||
errorMsg = valFc.value +' is not an integer';
|
||||
return errorMsg;
|
||||
}
|
||||
if(!this.checkIfEmpty(valFc.value)&& inputType==='float'){
|
||||
errorMsg = 'input is not a decimal number (use . as a separator)';
|
||||
errorMsg = 'not a number (use . as a separator)';
|
||||
return errorMsg;
|
||||
}
|
||||
if(!this.checkIfEmpty(valFc.value)&& inputType==='boolean'){
|
||||
errorMsg = 'please enter true or false';
|
||||
return errorMsg;
|
||||
}
|
||||
if(!this.checkIfEmpty(valFc.value)&& inputType==='date'){
|
||||
errorMsg = 'date or date format is not correct';
|
||||
return errorMsg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue