[英]Angular Schema Form - “required” not working select and checkbox fields
我是Angular Schema Form的新手, select
和checkbox
字段存在一些問題, required
驗證。
在$scope.schema
我有選擇字段命名designation
:
"designation": {
"title": "Designation",
"type": "select",
"default": undefined
}
$scope.form
(聲明designation
和agreeTerms
):
{
"key": "designation",
"type": "select",
"title": "Designation",
"titleMap": [
{ value: undefined, name: "Select a designation" }, // first value
{ value: "Andersson", name: "Andersson" },
{ value: "Johansson", name: "Johansson" },
{ value: "other", name: "Something else..."}
]
},
{
"key": "agreeTerms",
"type": "checkbox",
"title": "I agree to ..."
}
在模式的required
屬性中定義了designation
和agreeTerms
。
當我提交表單時,兩個字段均通過了required
驗證。 我希望用戶界面顯示的是字段下方/之后的Required
消息。 那沒有發生。
我嘗試過的事情:
''
並為null
並將其與架構默認值匹配。 select
字段類型更改為架構中的object
; 這有效並通過了所需的驗證,但該屬性未顯示在模型中 請幫忙 :)
您需要將架構類型更改為string
因為select
不是有效的架構type
屬性。
"designation": {
"title": "Designation",
"type": "string",
"default": undefined
}
然后,在表單標簽中,您應該具有ng-submit =“ submitForm(ngform,modelData)” :
<form sf-schema="schema" sf-form="form" sf-model="model" ng-submit="submitForm(ngform,modelData)" sf-options="option"></form>
然后,您可以在控制器中廣播提交后進行驗證:
$scope.submitForm = function(form) {
// First we broadcast an event so all fields validate themselves
$scope.$broadcast('schemaFormValidate');
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.