-
Notifications
You must be signed in to change notification settings - Fork 169
Dynamic Schema issues in array #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="ISO-8859-1"> | ||
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> | ||
<link rel="stylesheet" type="text/css" href="../dist/css/brutusin-json-forms.min.css"> | ||
|
||
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | ||
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
<script type="text/javascript" charset="utf8" src="../dist/js/brutusin-json-forms.js"></script> | ||
<script type="text/javascript" charset="utf8" src="../dist/js/brutusin-json-forms-bootstrap.min.js"></script> | ||
</head> | ||
<body> | ||
<div id="formDialog" class="modal fade"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title pull-left"></h4> | ||
<div class="btn-toolbar pull-right formDialogControlsGroup"> | ||
<button type="button" class="btn btn-sm btn-warning" id="formDialogCancel" data-dismiss="modal">Cancel</button> | ||
</div> | ||
</div> | ||
<div id="formDialogBody" class="modal-body"> | ||
<div id="formDialogContainer"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
<script> | ||
$(document).ready(function() { | ||
var formSchema = { | ||
"$schema": "http://json-schema.org/draft-03/schema#", | ||
"type": "object", | ||
"properties": { | ||
"speciesList": { | ||
"type": "array", | ||
"title": "List of species", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"species": { | ||
"title": "Species supported", | ||
"description": "Changes in this property (`$.speciesList[#].species`) trigger the resolution of the actual (depending on the values being selected) schema of a dependent property (`$.speciesList[#].subspecies`)", | ||
"type": "string", | ||
"enum": [ | ||
"human", | ||
"dog", | ||
"cat" | ||
], | ||
"required": true | ||
}, | ||
"subspecies": { | ||
"dependsOn": [ | ||
"species" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
var BrutusinForms = brutusin["json-forms"]; | ||
var schemaResolver = function(names, data, cb) { | ||
var schemas = new Object(); | ||
var schema = new Object(); | ||
var idx = data.speciesList.length - 1; | ||
|
||
if (data.speciesList[idx].species === "human") { | ||
schema.type = "null"; // no such property for humans | ||
} else { | ||
schema.type = "string"; | ||
if (data.speciesList[idx].species === "dog") { | ||
schema.title = "Dog breed"; | ||
schema.enum = ["bulldog", "labrador"] | ||
} else { | ||
schema.title = "Cat breed"; | ||
schema.enum = ["siamese", "persian"] | ||
} | ||
} | ||
schemas["$.speciesList[#].subspecies"] = schema; | ||
setTimeout(function(){cb(schemas)},500); // in order to show asynchrony | ||
}; | ||
|
||
var form = BrutusinForms.create(formSchema); | ||
form.schemaResolver = schemaResolver; | ||
|
||
form.render(document.getElementById("formDialogContainer")); | ||
|
||
var dialog = $("#formDialog"); | ||
dialog.modal(); | ||
}); | ||
</script> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="ISO-8859-1"> | ||
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> | ||
<link rel="stylesheet" type="text/css" href="../dist/css/brutusin-json-forms.min.css"> | ||
|
||
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | ||
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
<script type="text/javascript" charset="utf8" src="../dist/js/brutusin-json-forms.js"></script> | ||
<script type="text/javascript" charset="utf8" src="../dist/js/brutusin-json-forms-bootstrap.min.js"></script> | ||
</head> | ||
<body> | ||
<div id="formDialog" class="modal fade"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title pull-left"></h4> | ||
<div class="btn-toolbar pull-right formDialogControlsGroup"> | ||
<button type="button" class="btn btn-sm btn-warning" id="formDialogCancel" data-dismiss="modal">Cancel</button> | ||
</div> | ||
</div> | ||
<div id="formDialogBody" class="modal-body"> | ||
<div id="formDialogContainer"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
<script> | ||
$(document).ready(function() { | ||
var formSchema = { | ||
"$schema": "http://json-schema.org/draft-03/schema#", | ||
"type": "object", | ||
"definitions": { | ||
"name": { | ||
"type": "string", | ||
"title": "Name", | ||
"required": true, | ||
"pattern": "^[A-Za-z][0-9a-zA-Z-_ ]{7,}$", | ||
"description": "Mandatory alphanumeric starting with an alphabet. Space, hyphen and underscore allowed. Min length: 8" | ||
}, | ||
"options": { | ||
"type": "string", | ||
"title": "Options", | ||
"required": true, | ||
"enum": ["OPTION-1", "OPTION-2", "OPTION-3"], | ||
"description": "Mandatory option" | ||
}, | ||
"level2Array": { | ||
"type": "array", | ||
"title": "Level-2 Array", | ||
"description": "List of Level-2 items", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"$ref": "#/definitions/name" | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"properties": { | ||
"name": { | ||
"$ref": "#/definitions/name" | ||
}, | ||
"level1Array": { | ||
"type": "array", | ||
"title": "Level-1 Array", | ||
"description": "List of Level-1 items", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"option": { | ||
"$ref": "#/definitions/options" | ||
}, | ||
"level2Array": { | ||
"dependsOn": [ "option" ] | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
var BrutusinForms = brutusin["json-forms"]; | ||
var schemaResolver = function(names, data, cb) { | ||
var schemas = new Object(); | ||
var schema = { "$ref": "#/definitions/level2Array" }; | ||
var optIdx; | ||
|
||
if(data && data.level1Array && data.level1Array.length) { | ||
optIdx = data.level1Array.length-1; | ||
if(data.level1Array[optIdx].option !== "OPTION-1") { | ||
schema = { type: "null" }; | ||
} | ||
} | ||
|
||
schemas["$.level1Array[#].level2Array"] = schema; | ||
setTimeout(function(){cb(schemas)},500); | ||
}; | ||
|
||
var form = BrutusinForms.create(formSchema); | ||
form.schemaResolver = schemaResolver; | ||
|
||
form.render(document.getElementById("formDialogContainer")); | ||
|
||
var dialog = $("#formDialog"); | ||
dialog.modal(); | ||
}); | ||
</script> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,7 @@ if (typeof brutusin === "undefined") { | |
} else if (s.media) { | ||
input = document.createElement("input"); | ||
input.type = "file"; | ||
appendChild(input, option, s); | ||
// XXX TODO, encode the SOB properly. | ||
} else if (s.enum) { | ||
input = document.createElement("select"); | ||
|
@@ -204,7 +205,7 @@ if (typeof brutusin === "undefined") { | |
} | ||
} | ||
if (s.enum.length === 1) | ||
input.selectedIndex = 0; | ||
input.selectedIndex = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This must be: Will change and re-submit |
||
else | ||
input.selectedIndex = selectedIndex; | ||
} else { | ||
|
@@ -222,10 +223,6 @@ if (typeof brutusin === "undefined") { | |
// #46, problem in IE11. TODO polyfill? | ||
input.type = "text"; | ||
} | ||
} else if (s.format === "date") { | ||
input.type = "date"; | ||
} else if (s.format === "time") { | ||
input.type = "time"; | ||
} else if (s.format === "email") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deletion of above 4 lines unintended. Will add these in my version and re-submit the pull request. |
||
input.type = "email"; | ||
} else if (s.format === "text") { | ||
|
@@ -349,7 +346,7 @@ if (typeof brutusin === "undefined") { | |
input = document.createElement("input"); | ||
input.type = "checkbox"; | ||
if (value === true || value !== false && s.default) { | ||
input.checked = true; | ||
input.checked = true; | ||
} | ||
} else { | ||
input = document.createElement("select"); | ||
|
@@ -750,7 +747,6 @@ if (typeof brutusin === "undefined") { | |
if (s.readOnly) | ||
addButton.disabled = true; | ||
addButton.setAttribute('type', 'button'); | ||
addButton.className = "addItem"; | ||
addButton.getValidationError = function () { | ||
if (s.minItems && s.minItems > table.rows.length) { | ||
return BrutusinForms.messages["minItems"].format(s.minItems); | ||
|
@@ -831,7 +827,7 @@ if (typeof brutusin === "undefined") { | |
|
||
obj.getData = function () { | ||
function removeEmptiesAndNulls(object, s) { | ||
if (s === null) { | ||
if (!s) { | ||
s = SCHEMA_ANY; | ||
} | ||
if (s.$ref) { | ||
|
@@ -1311,7 +1307,7 @@ if (typeof brutusin === "undefined") { | |
|
||
function cleanSchemaMap(schemaId) { | ||
for (var prop in schemaMap) { | ||
if (prop.startsWith(schemaId)) { | ||
if (prop.startsWith(schemaId)) { // 02_AddLevel1Item_Delete_AgainAdd.png | ||
delete schemaMap[prop]; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surprisingly, in the origin itself, the code differs between
|
||
|
@@ -1413,7 +1409,7 @@ if (typeof brutusin === "undefined") { | |
throw ("Node '" + name + "' is of type array"); | ||
} | ||
var element = currentToken.substring(1, currentToken.length - 1); | ||
if (element.equals("#")) { | ||
if (element === "#") { | ||
for (var i = 0; i < data.length; i++) { | ||
var child = data[i]; | ||
visit(name + currentToken, queue.slice(0), child, data, i); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addition of this line is unintended. I will remove this line from my version and resubmit the pull request.