Angular 模式表单 - "required" 不工作 select 和复选框字段
Angular Schema Form - "required" not working select and checkbox fields
我是 Angular 架构表单的新手,在 select
和 checkbox
字段 required
验证方面遇到了一些问题。
在 $scope.schema
下,我有一个名为 designation
:
的 select 字段
"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 ..."
}
designation
和 agreeTerms
都在架构的 required
属性 中定义。
当我提交表单时,两个字段都通过了 required
验证。我期望 UI 显示的是 Required
消息 underneath/after 字段。那不会发生。
我尝试过的事情:
- 将 select 字段的第一个值分配给
''
和 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');
};
我是 Angular 架构表单的新手,在 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 ..."
}
designation
和 agreeTerms
都在架构的 required
属性 中定义。
当我提交表单时,两个字段都通过了 required
验证。我期望 UI 显示的是 Required
消息 underneath/after 字段。那不会发生。
我尝试过的事情:
- 将 select 字段的第一个值分配给
''
和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');
};