我确实有一个输入字段,其中填充了JSON对象数据。
dimension: {
length: 10.00,
width: 20.00,
height: 30.00,
}
输入如下所示:
<input matInput [placeholder]="Dimension (LxHxW)" formControlName="dimensions"
name="dimensions" mask="00.0x00.0x00.0" [specialCharacters]="['x', '.']"
[clearIfNotMatch]="true" [showMaskTyped]="true"
/>
其中维度在 typescript 代码中内置为:
let dimensions = null;
if (dimensionObject) {
dimensions = '' + dimensionObject.length + 'x' + dimensionObject.width + 'x'
+ dimensionObject.height;
}
The goal is to map correctly the data on the mask and obtain the length, width and height concatenated with an x in between-> obtain a flexible mask.
当维度值的长度不同时会出现问题:
例如如果尺寸为 2.3 x 12.3 x 42.2 而不是 2.3 x 12.3 x 42.2,它将显示 23.1 x 23.4 x 22。(x 偏移)。
你们能找到任何解决方案吗?
最佳答案
我猜你必须使用模式
以下示例,取自this article on CSS-tricks, by Chris Coyier但是created by Estelle Weyl ,展示如何使用 A1A 1A1 形式处理加拿大邮政编码:
<div> <label for="czc">Canadian Zip Code</label> <input id="czc" placeholder="XXX XXX" pattern="\w\d\w \d\w\d" class="masked" data-charset="_X_ X_X" id="zipca" type="text" name="zipcodeca" title="6-character alphanumeric zip code in the format of A1A 1A1" /> </div>
在您的情况下,您应该只更改模式正则表达式。
关于angular - 自定义 Angular 输入掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54765939/