【发布时间】:2016-11-17 07:54:52
【问题描述】:
我已经启动了一个 Aurelia 项目,并选择使用 this plugin 来启用电话号码的输入屏蔽,使用类似于 this post 中的实现。
它在 Chrome 和 Safari 中运行良好 - 但是,它在 Firefox 中无法正常运行。没有错误或其他有用的信息。但是,上面链接的演示页面上的示例工作得很好,所以我确信它一定与我的实现有关:
JS:
import {inject, NewInstance} from 'aurelia-dependency-injection';
import {ValidationController, ValidationRules, validateTrigger} from 'aurelia-validation';
import 'igorescobar/jQuery-Mask-Plugin'
@inject(NewInstance.of(ValidationController))
export class MyForm {
async activate(params, routeConfig) {
// do stuff if there are route parameters
}
bind() {
$('#PhoneNumber').mask('(000) 000-0000');
}
constructor(controller) {
this.controller = controller;
this.controller.validateTrigger = validateTrigger.manual;
}
submit() {
this.controller.validate()
.then(errors => {
if (errors.length === 0) {
// do a thing
} else {
// do something else
}
});
}
}
ValidationRules
.ensure('phoneNumber').displayName('Phone number')
.minLength(10).withMessage('Phone number must be at least 10 characters')
.maxLength(14).withMessage('Phone number is too long')
.matches(/[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}/).withMessage('Please provide a valid phone number')
.on(MyForm);
HTML
<input class="form-control" id="PhoneNumber" type="tel" minlength="10" maxlength="14" pattern="[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}" value.bind="phoneNumber & validate" required="required">
我尝试删除模式属性并将其更改为常规文本输入,但无济于事。我真的在这个问题上摸不着头脑。任何想法或建议将不胜感激。
【问题讨论】:
标签: jquery firefox jquery-plugins aurelia jspm