We have a web app containing several forms, the majority of them with a few dozen fields. Right now we create json objects with the data entered in the forms and send those objects to REST services which, in turn, persist that data into a NoSQL database (MongoDB).
Currently, we´re using jquery-validator to perform validation at client side. However, we require to validate the data using the same JSONSchema (both on client and server sides).
Is there any way to use jquery-validate (or other similar plugin) to do this? I'm thinking maybe there is a way to replace the "rules" defined for jquery-validate with the JSONSchema file.
I've tried using "Alpaca" which can both generate and validate the forms using JSONSchema, but the problem I've come across with Alpaca is that it's not capable of handling nested json objects, which I have a lot of, it only seems to work with simple json structures.
Any help would be greatly appreciated.
UPDATE
Let's say I have the following jquery-validate rules (fairly simple for example purposes):
$('#formId').validate({
rules: {
firstField: {
required: true
},
secondField: {
required: true,
maxlength: 80
}
}
});
And I have the following JSONSchema file:
{
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "object",
"additionalProperties": false,
"description": "MyJsonSchema",
"properties": {
"firstField": {
"description": "some text here",
"type": "string",
"maxLength": 15,
"required": true
},
"secondField": {
"description": "some text here",
"type": "string",
"maxLength": 80,
"required": true
}
}
}
What I would like to do is find a way to replace the "rules" from the jquery-validate plugin and instead just read the JSONSchema properties, so that I have the validation rules for all my forms in the JSONSchema files (which I can use for client side and server side validation) instead of coding the rules for every form.
Is there any way to do that?
As I've said before, using something like AlpacaJS you can render and validate the forms from a JSONSchema file, but I haven't being able to use Alpaca with more complex json structures.