[英]Angular Schema Form - “required” not working select and checkbox fields
I'm new to Angular Schema Form and having some issues with select
and checkbox
fields required
validation. 我是Angular Schema Form的新手,
select
和checkbox
字段存在一些问题, required
验证。
Under $scope.schema
I have the select field named designation
: 在
$scope.schema
我有选择字段命名designation
:
"designation": {
"title": "Designation",
"type": "select",
"default": undefined
}
$scope.form
(declaring designation
and agreeTerms
): $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 ..."
}
Both designation
and agreeTerms
are defined in the schema's required
property. 在模式的
required
属性中定义了designation
和agreeTerms
。
When I submit the form, both fields however pass the required
validation. 当我提交表单时,两个字段均通过了
required
验证。 What I'm expecting the UI to show are the Required
messages underneath/after the fields. 我希望用户界面显示的是字段下方/之后的
Required
消息。 That is not happening. 那没有发生。
Things I've tried: 我尝试过的事情:
''
and null
and match that with the schema default value. ''
并为null
并将其与架构默认值匹配。 select
field type to object
in the schema; select
字段类型更改为架构中的object
; this worked and passed the required validation but the property didn't show up in the model Please help :) 请帮忙 :)
You need to change the schema type to string
as select
is not a valid schema type
property. 您需要将架构类型更改为
string
因为select
不是有效的架构type
属性。
"designation": {
"title": "Designation",
"type": "string",
"default": undefined
}
Then in your form tag you should have ng-submit="submitForm(ngform,modelData)" : 然后,在表单标签中,您应该具有ng-submit =“ submitForm(ngform,modelData)” :
<form sf-schema="schema" sf-form="form" sf-model="model" ng-submit="submitForm(ngform,modelData)" sf-options="option"></form>
Then within your controller you can broadcast on submit to validate: 然后,您可以在控制器中广播提交后进行验证:
$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.