wintercms / wn-builder-plugin

GUI for building plugins in Winter CMS
MIT License
34 stars 12 forks source link

Automatically populate $jsonable field in the model for certain field types #21

Closed qroft closed 2 years ago

qroft commented 2 years ago

Winter CMS Build

1.1

PHP Version

7.4

Database engine

MySQL/MariaDB

Plugins installed

Winter.Builder,Rainlab.User

Issue description

Within the builder plugin i have created a DB with a column called "settingsO" as "Text" with a length of 65535. Then in my models for this DB, i went to Forms -> fields.yaml and created a "Checkbox List" with three options.

It does not matter if i choose one, two or all options from within my form in the backend, i always get this error: "Unexpected type of array when attempting to save attribute "settingsO", try adding it to the $jsonable property." on line 781 of /htdocs/vendor/winter/storm/src/Database/Model.php

Steps to replicate

  1. Create a DB with some tables, one saying something like "mySettings".
  2. Create a Model for said DB.
  3. Add a Form
  4. Add the widget "Checkbox List" to that form and save.
  5. Go to your form in the backend and try to add a new entry.

Workaround

No response

qroft commented 2 years ago

Thank you @bennothommo for clearifying this. I am a dev-noob and often do not know how to make these entries right. Nevertheless i do have question about this: Can you put in here the structure on how the "Checkbox List" data is saved inside the MySql DB? I am asking, so that i can put my data in the table manually how the widget would love to see it until the bug is eleminated. Thanks in advance!

LukeTowers commented 2 years ago

@qroft to fix the issue for yourself manually, simply add the attribute you're using for the checkboxlist field to the $jsonable property on your model, see https://wintercms.com/docs/database/model#property-jsonable for more information.

bennothommo commented 2 years ago

@LukeTowers we probably should add to the docs any fields that might need to be stored as $jsonable (like the checkbox list, or repeater). Currently, I believe, we only make this clear for the data table widget. Perhaps we can also indicate that these fields should be stored as a TEXT type or a JSON type in the DB.