-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add partial form support #449
base: master
Are you sure you want to change the base?
Conversation
Might make more sense to call this |
It seems like this might be better as a pre-processing step before instantiating a JSON Editor instance. That way there's no need to mess with the core, which may have unintended consequences. For example: // Full schema
var schema = {...};
// Get subschema from path (is there a better function name?)
var subschema = JSONEditor.getSubschema(schema, "properties.containers.items.properties.base");
// Use this subschema when creating the editor
var editor = new JSONEditor(element, {
schema: subschema
}); |
But then you lose references to definitions in the schema, since the subschema doesn't contain them. If you do |
I actually tried the subschema helper method, and made it preserve the definitions and such. Here is what it looks like: JSONEditor.getSubschema = function (schema, path) {
return {
$schema: schema.$schema,
definitions: schema.definitions ? $.extend(true, {}, schema.definitions) : undefined,
type: schema.type,
properties: $.extend(true, {}, $walk(path, schema.properties))
};
}; Ignore the use of jQuery's extend there, just needed a quick deep clone. The problem is if you use it like this: // Get subschema from path (is there a better function name?)
var subschema = JSONEditor.getSubschema(schema, "containers.items.properties.base"); You get out a schema that looks like: {
"$schema": "http://json-schema.org/schema#",
"definitions": { /* ... */ },
"type": "object",
"properties": {
"$ref": "#/definitions/containerInfo"
}
} And that doesn't work, the |
|
That makes sense, but AFAIK the methods that would be what I used for this are instance methods. So you would have to create the instance first, flatten the schema using utility methods on the instance, then use that flattened schema to create another JSONEditor instance with the correct schema. I feel like there is a better way... |
This adds a new option
root_schema
that is a dot-notated string that describes a sub-section of a schema to use when generating the form.This is useful when you have a schema with definitions and other shared items, but different parts of the schema need to be in different forms (for example in different tabs like #331). This makes that possible.
Usage example:
This will generate a form for just the "base" object, which in my case is necessary. I can then put the variant form on a separate tab, and keep all the other values ("id", etc) out of the form completely.