【问题标题】:Backspace doesn't work in Firefox Angular 2退格在 Firefox Angular 2 中不起作用
【发布时间】:2019-06-14 18:49:19
【问题描述】:

我有一个输入字段(输入文本),我必须避免在其中引入任何没有数字的字符。此外,该字段仅限于 4 个数字(一年字段)。 当我得到它时,该字段不允许使用退格键或键盘上的删除键。

我从这个页面尝试了几个解决方案,但没有一个对我有用。

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

.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 个字符的字段,只有数字,我可以随时擦除任何更改。

【问题讨论】:

  • 也许您应该尝试重构您的解决方案。阅读更多stackoverflow.com/questions/34556035/…
  • 感谢@NicolaeOlariu 的回答。如果你看到代码,我们不使用表格而不是 HTML 代码。这个解决方案对我不起作用。

标签: angular firefox backspace


【解决方案1】:

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

尽管如此,可能是 Mozilla Forum 的另一种解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 2017-06-20
    • 2017-04-17
    • 2014-12-17
    • 2018-10-19
    相关资源
    最近更新 更多