HTML5 date input control custom validation based on JSON Schema -
in application using backbone, have json object tells display html5 controls,
"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" } ]
and value entered user validated using json schema,
"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"} }
the required field validation working fine. need have age restriction validation age must 18 or older. how can add custom validation json schema triggered in ui?
thanks in advance.
backbone view code.
render: function () { // code add form template 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 persist} }
Comments
Post a Comment