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

Group fields in JSON column #162

Closed
nsivertsen opened this issue Jan 20, 2019 · 3 comments
Closed

Group fields in JSON column #162

nsivertsen opened this issue Jan 20, 2019 · 3 comments
Labels
type: enhancement New feature or request

Comments

@nsivertsen
Copy link
Contributor

Hi there!

I was wondering whether there's already some infrastructure in place to group a set of fields in a module in such a way that they are saved to one JSON column in the database, both for fields on the module itself and for fields in blocks?

The reason for doing this is that I'm using the connected fields partial to show or hide some fields based on other fields and I'd prefer not to have a database column for every possible field. Also, I can foresee adding more fields to this field group later on.

I've managed to save a set of fields to one JSON field in the database using the prepareFieldsBeforeSave hook the the module repository, but I'm having trouble getting them back into the form. If I add them to the $fields array in the getFormFields hook they are ignored.

Is there maybe a better way?

Thank you!

@zipavlin
Copy link
Contributor

zipavlin commented Jan 22, 2019

@nsivertsen this is a great idea! It could be packed into new 'group' field :)
Please share if you will manage to get it to work.

It would be a step towards having page/field templates (#126)

@ifox
Copy link
Member

ifox commented Jan 23, 2019

Hi @nsivertsen,

Like I just mentioned in #164, this is a great idea.

We do not have the infrastructure immediately in place to be able to do that, however our blocks content works exactly like that so we should be able to leverage that part of the codebase to implement something at the module level.

In the meantime that's definitely something that should be achievable through the repository.
Which fields were you using? input, wysiwyg, select, radios, multi_select, checkbox and checkboxes should be compatible when added manually to $fields in getFormFields.

Another approach that should work for more field types would be to deconstruct the JSON into multiple Eloquent model accessors, but that would be way to much infrastructure to solve an issue that should make things simpler.

@ifox ifox added the type: enhancement New feature or request label Jan 23, 2019
@yanhao-li
Copy link

If you are trying to render the select formFields use getFormFields, it might related to #175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants