restricted input of '

This commit is contained in:
Akash Shah 2019-07-17 11:27:05 -04:00
parent 003ff7f802
commit 987d4420ba
4 changed files with 28 additions and 7 deletions

View File

@ -4,7 +4,7 @@ import {ToastManagerService} from '../../services/toast-manager/toast-service.se
@Component({ @Component({
selector: 'app-empty-error-editor', selector: 'app-empty-error-editor',
template: ` template: `
<input #i class="w-100" [value]="params.value" (keydown)="onKeyDown($event)"/> <input #i class="w-100" [value]="params.value" (keypress)="onKeyPress($event)" (keydown)="onKeyDown($event)"/>
` `
}) })
export class EmptyErrorEditorComponent implements AfterViewInit { export class EmptyErrorEditorComponent implements AfterViewInit {
@ -27,6 +27,23 @@ export class EmptyErrorEditorComponent implements AfterViewInit {
return this.textInput.nativeElement.value; return this.textInput.nativeElement.value;
} }
onKeyPress(event) {
if (event.key === '\'') {
event.preventDefault();
this.notif('Cannot use \' (apostrophes)');
setTimeout(() => {
this.textInput.nativeElement.focus();
});
}
if (event.key === '\'') {
event.preventDefault();
this.notif('Cannot use \' (apostrophes)');
setTimeout(() => {
this.textInput.nativeElement.focus();
});
}
}
onKeyDown(event) { onKeyDown(event) {
if (event.keyCode === 9 || event.keyCode === 13) { if (event.keyCode === 9 || event.keyCode === 13) {
if (!this.textInput.nativeElement.value) { if (!this.textInput.nativeElement.value) {

View File

@ -4,7 +4,7 @@ import {ToastManagerService} from '../../services/toast-manager/toast-service.se
@Component({ @Component({
selector: 'app-in-det-qty-editor', selector: 'app-in-det-qty-editor',
template: ` template: `
<input #i type="number" min="0" [max]="remainingQty" class="w-100" [value]="params.value" (keydown)="onKeyDown($event)"/> <input #i type="number" min="0" class="w-100" [step]="remainingQty/100" [value]="params.value" (keydown)="onKeyDown($event)"/>
` `
}) })
export class InDetQtyEditorComponent implements AfterViewInit { export class InDetQtyEditorComponent implements AfterViewInit {
@ -37,9 +37,11 @@ export class InDetQtyEditorComponent implements AfterViewInit {
setTimeout(() => { setTimeout(() => {
this.numberInput.nativeElement.focus(); this.numberInput.nativeElement.focus();
}); });
} else if (this.numberInput.nativeElement.value < 0 || this.numberInput.nativeElement.value > this.remainingQty) { } else if (!(this.numberInput.nativeElement.value >= 0
&& parseInt((this.numberInput.nativeElement.value * 100000).toFixed(0), 10) -
parseInt((this.remainingQty * 100000).toFixed(0), 10) <= 1)) {
event.stopPropagation(); event.stopPropagation();
this.notif('Value should between 0 and ' + this.remainingQty); this.notif('Value should between 0 and ' + this.remainingQty.toPrecision(2));
setTimeout(() => { setTimeout(() => {
this.numberInput.nativeElement.focus(); this.numberInput.nativeElement.focus();
}); });

View File

@ -45,7 +45,7 @@
<span class="input-group-text">ID*</span> <span class="input-group-text">ID*</span>
</td> </td>
<td colspan="7"> <td colspan="7">
<input type="text" class="form-control" placeholder="johndoe" #inId> <input type="text" class="form-control" [textMask]="{mask: idMask, guide: false}" placeholder="johndoe" #inId>
</td> </td>
</tr> </tr>
@ -135,7 +135,7 @@
<tr> <tr>
<td style="width: 1%"> <td style="width: 1%">
<span class="input-group-text">Ext*</span> <span class="input-group-text">Ext</span>
</td> </td>
<td colspan="3"> <td colspan="3">
<input type="tel" class="form-control" placeholder="123456" #inPhExt [value]=""> <input type="tel" class="form-control" placeholder="123456" #inPhExt [value]="">

View File

@ -32,7 +32,7 @@ export class CustomerComponent implements OnInit {
{headerName: 'Address 2 ✎', field: 'add2', editable: true, cellEditor: 'emptyErrorEditorComponent'}, {headerName: 'Address 2 ✎', field: 'add2', editable: true, cellEditor: 'emptyErrorEditorComponent'},
{headerName: 'City ✎', field: 'city', editable: true, cellEditor: 'emptyErrorEditorComponent'}, {headerName: 'City ✎', field: 'city', editable: true, cellEditor: 'emptyErrorEditorComponent'},
{headerName: 'State ✎', field: 'state', editable: true, cellEditor: 'emptyErrorEditorComponent'}, {headerName: 'State ✎', field: 'state', editable: true, cellEditor: 'emptyErrorEditorComponent'},
{headerName: 'ZIP ✎', field: 'zip', editable: true, cellEditor: 'emptyErrorEditorComponent'}, {headerName: 'ZIP ✎', field: 'zip', editable: true, cellEditor: 'numericEditorComponent'},
{headerName: 'ZIP-4 ✎', field: 'ziplast4', editable: true, cellEditor: 'numericEditorComponent'} {headerName: 'ZIP-4 ✎', field: 'ziplast4', editable: true, cellEditor: 'numericEditorComponent'}
]; ];
frameworkComponents = { frameworkComponents = {
@ -109,6 +109,8 @@ export class CustomerComponent implements OnInit {
{headerName: 'Address ✎', field: 'address', editable: true} {headerName: 'Address ✎', field: 'address', editable: true}
]; ];
idMask = [/[^']/, /[^']/, /[^']/, /[^']/, /[^']/, /[^']/, /[^']/, /[^']/, /[^']/, /[^']/];
// address: "123 Test Drive" // address: "123 Test Drive"
// contactId: 1 // contactId: 1
// customerId: "MDOT" // customerId: "MDOT"