Skip to content
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

Advanced_view does not work with JSON arrays #5

Open
sedubois opened this issue Oct 28, 2019 · 4 comments
Open

Advanced_view does not work with JSON arrays #5

sedubois opened this issue Oct 28, 2019 · 4 comments

Comments

@sedubois
Copy link

sedubois commented Oct 28, 2019

Currently it is not possible to use the advanced_view option for displaying JSON arrays as the code is defined as follows:

      def advanced_view?
        advanced_view.present? && advanced_view.is_a?(Hash)
      end

E.g if the JSON value is ["one", "two", "three"], it would be nice to be able to just display one, two, three instead of the heavy-looking jsoneditor, and also this advanced_view is necessary to enforce the structure of the data (e.g ensuring the editor won't enter a hash when an array should be provided).

@volkov-sergey
Copy link
Member

Hey @sedubois nice catch, thanks. What do you think will be the most comfortable way to use an array feature?

Something like this:

Field::JSONB.with_options(array: true)

or

Field::JSONB.with_options(advanced_view: [])

Share your opinion, please

@sedubois
Copy link
Author

sedubois commented Oct 29, 2019

@volkov-sergey at first thought I would use another name than "advanced view", technically what is being described here is a description of the JSON's schema. E.g for both arrays and objects:

# JSON array
Field::JSONB.with_options(schema: Field::JSONB::Array(
  Field::String
))
# JSON object
Field::JSONB.with_options(schema: Field::JSONB::Hash(
  'name'  => Field::String,
  ...
))

Or something like that.

Then there is the (separate) question of how to render the form and data, either with jsoneditor or custom. To start, could just use custom views when schema is provided (like now). Then as a second step there could be a way to control this too (either by passing a render option, or by letting user override views).

@volkov-sergey
Copy link
Member

@sedubois working on it

@uysimatpassbase
Copy link

How is it going for this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants