diff --git a/src/app/widgets/inlineinput/inlineinput.component.ts b/src/app/widgets/inlineinput/inlineinput.component.ts index 8f5eac992..bc9f83934 100644 --- a/src/app/widgets/inlineinput/inlineinput.component.ts +++ b/src/app/widgets/inlineinput/inlineinput.component.ts @@ -72,6 +72,7 @@ export class InlineInputComponent implements OnInit { }); } else { this.errorMessage = `Invalid value for the field type ${this.type}`; + this.inputField.nativeElement.focus(); } } @@ -83,12 +84,17 @@ export class InlineInputComponent implements OnInit { } } + isFloat(val) { + let x = parseFloat(val); + return typeof x === 'number' && Number.isFinite(x) && x >= -2147483648 && x <= 2147483648; + } + validateValue(value) { if (this.type === 'integer') { return /^\d+$/.test(value); } if (this.type === 'float') { - return /^-?\d*(\.\d+)?$/.test(value); + return this.isFloat(value); } return true; } @@ -161,6 +167,9 @@ export class InlineInputComponent implements OnInit { break; } } + if (this.editing && this.type == 'float' && keycode == 13) { + this.saveClick(); + } if (this.isNotValid) { this.errorMessage = `This is a ${this.type} field`; } diff --git a/src/app/widgets/inlineinput/inlineinput.spec.ts b/src/app/widgets/inlineinput/inlineinput.spec.ts new file mode 100644 index 000000000..ee291a2ba --- /dev/null +++ b/src/app/widgets/inlineinput/inlineinput.spec.ts @@ -0,0 +1,41 @@ +import { async } from '@angular/core/testing'; +import { InlineInputComponent } from './inlineinput.component'; + +describe('Unit Test :: Inline Input Float value', () => { + let comp = new InlineInputComponent(); + beforeEach(async(() => { + comp.type = 'float'; + })); + + it('Should return true for input 2234.523 in float range', () => { + expect(comp.validateValue('2234.523')).toBe(true); + }); + + it('Should return true for input 1.2 in float range', () => { + expect(comp.validateValue('1.2')).toBe(true); + }); + + it('Should return true for input 223456.334 in float range', () => { + expect(comp.validateValue('223456.334')).toBe(true); + }); + + it('Should return true for input 45 in float range', () => { + expect(comp.validateValue('45')).toBe(true); + }); + + it('Should return false for input -34567812322.523 outside float range', () => { + expect(comp.validateValue('-34567812322.523')).toBe(false); + }); + + it('Should return false for input 345678123225.23678 outside float range', () => { + expect(comp.validateValue('345678123225.23678')).toBe(false); + }); + + it('Should return false for input stringtest outside float range', () => { + expect(comp.validateValue('stringtest')).toBe(false); + }); + + it('Should return false for input 11111111111111111.51 outside float range', () => { + expect(comp.validateValue('11111111111111111.51')).toBe(false); + }); +});