基于JSON模式的HTML5日期输入控件自定义验证
在我使用主干网的应用程序中,我有一个JSON对象,它告诉我显示什么作为HTML5控件基于JSON模式的HTML5日期输入控件自定义验证,html,validation,date,backbone.js,Html,Validation,Date,Backbone.js,在我使用主干网的应用程序中,我有一个JSON对象,它告诉我显示什么作为HTML5控件 "items": [ { "key": "User.FName", "title" : "First Name" }, { "key" : "User.LName", "title": "Last Name" }, { "key": "User.DateofBirth
"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} }
处理这些JSON对象、创建HTML元素并验证元素输入的代码在哪里?除非您包含该代码,否则我们将无法提供大量帮助。要呈现的代码实际上很简单。在主干视图中,添加了一个jsonform,其中包含选项(JSON对象)、模式(JSON模式)和db中的值(如果已经添加)。在按钮提交事件中,在将值发送到api进行持久化之前,调用jsonform.validate()。我将编辑帖子以包含代码。
jsonForm
来自哪里?这不是内置的jQuery函数。啊,忘记了最有趣的部分。它使用从中获得的JSONForm插件。将这些模式转换为HTML5控件并提供验证。