簡體   English   中英

Angular Schema Form-“必需”不起作用的選擇和復選框字段

[英]Angular Schema Form - “required” not working select and checkbox fields

我是Angular Schema Form的新手, selectcheckbox字段存在一些問題, required驗證。

$scope.schema我有選擇字段命名designation

"designation": {
    "title": "Designation",
    "type": "select",
    "default": undefined
}

$scope.form (聲明designationagreeTerms ):

{
    "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屬性中定義了designationagreeTerms

當我提交表單時,兩個字段均通過了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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM