From c17b2572c1eaa3aa7b58e145eb6a775af0764fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 15 Nov 2023 13:01:50 +0000 Subject: [PATCH] fix: pab-table input: fix separator (.) for decimal value refs #628 --- jalhyd_branch | 2 +- .../pab-table/pab-table.component.html | 6 ++--- .../pab-table/pab-table.component.ts | 24 ++++++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/jalhyd_branch b/jalhyd_branch index de46203d5..d64531f13 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -350-modifier-l-avertissement-de-limite-d-ennoiement-de-villemonte +devel diff --git a/src/app/components/pab-table/pab-table.component.html b/src/app/components/pab-table/pab-table.component.html index d3b0c017e..733be4fb2 100644 --- a/src/app/components/pab-table/pab-table.component.html +++ b/src/app/components/pab-table/pab-table.component.html @@ -86,9 +86,9 @@ [class.select]="isSelect(cell)" [attr.rowspan]="rowSpan(cell)" [attr.colspan]="colSpan(cell)" [title]="cellTitle(cell)"> - <input matInput *ngIf="isNumberInput(cell)" step="0.00000000000001" type="number" required - [ngModel]="getCellValue(cell)" (ngModelChange)="setCellValue(cell,$event)" - (input)="inputValueChanged($event, cell)"> + <input matInput *ngIf="isNumberInput(cell)" type="text" required + [ngModel]="getCellValue(cell)" (ngModelChange)="setCellValue(cell,$event)" + (input)="inputValueChanged($event, cell)" (keypress) ="invalidNANInputValue($event)"> <mat-select #selectWidget *ngIf="isSelect(cell)" [value]="cell.modelValue" (selectionChange)="loiDebitSelected($event, cell)"> diff --git a/src/app/components/pab-table/pab-table.component.ts b/src/app/components/pab-table/pab-table.component.ts index 8d48ab20a..897ba37c3 100644 --- a/src/app/components/pab-table/pab-table.component.ts +++ b/src/app/components/pab-table/pab-table.component.ts @@ -1388,12 +1388,24 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni return round(cell.model.singleValue, this.nDigits); } - public setCellValue(cell, event) { - try { - cell.model.singleValue = event - cell.modelValidity = undefined; - } catch (error) { - cell.modelValidity = false; + public setCellValue(cell, $event) { + if (/^-?[0-9]*\.?[0-9]*$/g.test($event) === false) { + $event = $event.replace(/[^0-9\-.]/g, ''); + } + if($event !== "-" && $event !== "") { + try { + cell.model.singleValue = $event; + cell.modelValidity = undefined; + } catch (error) { + cell.modelValidity = false + } + } + } + + public invalidNANInputValue(e: any) { + var rgx = /^-?[0-9]*\.?[0-9]*$/; + if(e.key.match(rgx) === null) { + e.preventDefault(); } } -- GitLab