我想在我的 Ember JS 应用程序中设置验证表单,测试数据库中是否存在电子邮件。
问题是我无法直接从 formValidators
调用我的商店。
formValidators: {
email: [
{
message: 'Please provide email in a valid format',
validate: (inputValue) => {
let emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
return emailPattern.test(inputValue);
}
},
{
message: 'Email already exist',
validate: (inputValue, self) => {
return this.get('store').queryRecord('email',
{
filter: {
email: inputValue
}
}).then(function () { return false })
}
}
]}
在 Chrome 控制台中运行时出现此错误:
TypeError: _this2.get is not a function(…)
我想知道这是一个很简单的问题,但我花了几个小时,不知道如何解决这个问题。
最佳答案
好的,我设置了一个操作:
validate(inputValue) {
this.get('store').queryRecord('buyer',
{
filter: {
email: inputValue
}
}).then(function (inputValue) {
console.log(inputValue)
});
}
并在输入 onChange 操作中:
onChange=(action "validate" validEmail)
但是还有另一个错误:
Assertion Failed: You must include an 'id' for buyer in an object passed to 'push'
关于javascript - 使用 ember.js 进行电子邮件验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39451318/