0

Backbone を使用するアプリケーションには、HTML5 コントロールとして何を表示するかを指示する JSON オブジェクトがあります。

     "items": [
                { "key": "User.FName", "title" : "First Name" },
                { "key" : "User.LName", "title": "Last Name" },
                {
                    "key": "User.DateofBirth",
                    "title": "Date of Birth",
                    "type": "date"
                },

                {
                    "type": "submit",
                    "title": "Check",
                    "htmlClass": "chkbtn"
                }
            ]

そして、ユーザーが入力した値は、この JSON スキーマを使用して検証され、

"User" : {
         "required" : true,
         "minItems" : 1,
         "properties" : {
                    "FName" : { "required": true, "title" : "First Name", "type" : "string"},  
                    "LName" : { "required": true, "title" : "Last Name", "type" : "string"},                          
                    "Salutation" : { "required": false, "title" : "Salutation", "type" : "string"},
                    "DateofBirth" : { "required": true, "title" : "Date Of Birth", "type" : "string"}
        }

必須フィールドの検証は正常に機能しています。しかし、年齢が 18 歳以上でなければならないという年齢制限の検証が必要です。カスタム検証をこの JSON スキーマに追加して、UI でトリガーできるようにするにはどうすればよいですか?

前もって感謝します。

バックボーン ビュー コード。

render: function () {

            // Code to add form from a template to el

            this.jsonForm = $("form").jsonForm({
                "schema": schema,
                "form": options,
                "value": vals
            });


        },

        submit: function (e) {

            var self = this;

            var err = this.jsonForm.validate();

            if (!err.errors) { // Code to persist} }
4

0 に答える 0