1
我有一个2字段,邮政编码和国家的窗体。 我需要根据国家选择以验证邮政编码,使用$验证如何根据Angular Schema Form中另一个字段的值验证字段?
这里是ngController代码
$scope.schema = {
"type": "object",
"title": "my form",
"properties": {
"postalCode": {
"title": "Postal Code",
"type": "string"
},
"countryCode": {
"title": "Country",
"type": "string",
"enum": [
"CA",
"US"
]
}
},
"required": [
"countryCode"
]
};
$scope.form = [{
"key": "postalCode",
$validators: {
// I would like to pass countryCode as the argument but doesn't work because I don't have model in my closure
postalCodeRegex: function (countryCodeValue) {
if (angular.isString(countryCodeValue)) {
var canada = "^(?!.*[DFIOQU])[A-VXY][0-9][A-Z]●?[0-9][A-Z][0-9]$";
if (/canada/.test(countryCodeValue)) return true;
else return false;
}
// if value is empty
return true;
}
}
},
"countryCode", {
"type": "submit",
"style": "btn-info",
"title": "OK"
}
];
有另一种方式来访问从$模型或范围验证器的逻辑?
plunker链接查看我的代码: http://plnkr.co/edit/DDbMiw?p=info