退格键在Firefox Angular 2中不起作用

时间:2019-06-07 12:26:56

标签: angular firefox backspace

我有一个输入字段(输入文字),我必须避免在此处引入任何没有数字的字符。而且,该字段限制为4个数字(是年字段)。 当我知道它时,该字段不允许使用退格键或从键盘上删除键。

我在此页面上尝试了几种解决方案,但没有一种适合我。

我认为问题与仅数字字段的限制有关,因为如果删除此选项,则键 backspace delete 正常!

.html是:

<tab heading="{{'Ressources du Foyer' | uppercase}}" [disabled]="!isEdit || !isODP">
                <table [defaultElemPerPage]="999" [data]="dataRessources" [config]="configRessources" [columns]="columnsRessources"
                    [showElementsPerPageSet]="false" [showItemNumberInfo]="false" [doHover]="false" [doClick]="false" [showActionsHeader]="!modeConsultation">
                    <template let-data>
                        <p class="text-center" *ngIf=!modeConsultation>
                            <a (click)="addRowLineRessources(data.index)" class="purple-icon" *ngIf="data.last" title="Ajouter une ligne"><span class="glyphicon glyphicon-plus"></span></a>
                            <a (click)="removeRowLineRessources(data.index)" title="Supprimer une ligne"><span class="purple-icon glyphicon glyphicon-trash"></span></a>
                        </p>
                    </template>
                </table>
            </tab>

.ts文件:

anneeReference: this.createStandardComponentService.createInputText({
        id: 'anneeReference',
        type: 'text',
        disabled: false,
        group: group.get('anneeReference'),
        errors: this.errors.anneeReference,
        outputMethod: this.validYear,
        maxlength: 4
      }),

validYear(event: any) {
    const pattern = Constants.NUMBERS_PATTERN;
    const codeCle = event.keyCode;
    const inputChar = String.fromCharCode(event.charCode);
    if (!pattern.test(inputChar) && (codeCle !== Constants.BACKSPACE_TOUCHE || codeCle !== Constants.DELETE_TOUCHE)) {
      event.preventDefault();
    }
  }

我希望该字段最多包含4个字符,只有数字,可以随时删除任何更改。

1 个答案:

答案 0 :(得分:0)

我通过另一种解决方法解决了该错误,删除了禁止我们添加任何非数字字符的过滤器(在客户接受之前,“因为这是对给出了规格)。

也许是 Mozilla Forum的另一种解决方案。

相关问题