ngx-schema-form icon indicating copy to clipboard operation
ngx-schema-form copied to clipboard

Adding fields to object

Open rgzr opened this issue 8 years ago • 4 comments

Can we achieve the following example? This is a simple one but it should be capable of handling more complex scenarios.

Given a schema like:

{"type":"object", "additionalProperties": {"type": "object", "properties": {"a": {"type":"string"}, "b": {"type": "number"}}}}

Could we have a button and an input in the object widget for adding properties like te ones defined in additionalProperties (one string input for "a" and one number input for "b").

rgzr avatar Sep 01 '17 11:09 rgzr

I think you should create a custom widget for this.

pankyka avatar Sep 04 '17 13:09 pankyka

How would that widget work? Which methods will it call to modify the model so that new sub-widgets are instantiated?

rgzr avatar Sep 06 '17 07:09 rgzr

@rgzr What kind of layout are you trying to accomplish? You can use the array type to add additional fields or widgets e.g. https://i.imgur.com/EDelEC3.jpg http://jsonformatter.org/ef5a2e

GFoley83 avatar Nov 28 '17 21:11 GFoley83

I'm using angular2-schema-form to allow users to produce a JSON that will be sent to a device that needs a JSON format file to work. I wrote a JSON schema describing the valid configurations that this schema can accept, which includes objects with arbitrary keys whose values can be one of multiple provided complex objects.

@GFoley83 with the example you give me I can only add string values to the array. What if the accepted values for the array are string and number? What if the accepted value is an object with properties? In any case, I need to add ANY type of value (given a JSON schema in an additionalProperties) including complex objects with properties, with the user provided key to an object. It will be great to allow the use of oneOf to offer the user the type of property to add to the object.

rgzr avatar Nov 29 '17 15:11 rgzr