octobercms / october

Self-hosted CMS platform based on the Laravel PHP Framework.
https://octobercms.com/
Other
11.01k stars 2.21k forks source link

Data error in a field of the nested form type when creating a model. #5759

Closed Dok2314 closed 11 months ago

Dok2314 commented 11 months ago

Example of my form.yaml:

fields: primary: label: Primary span: auto default: 0 type: switch section: label: Section nameFrom: name descriptionFrom: slug list: $/authorname/pluginname/models/modelname/recordfinder_columns_for_model.yaml span: full type: recordfinder custom_fields: type: nestedform showPanel: false dependsOn: section trigger: action: hide field: section condition: value form: fields:

Снимок экрана 2023-10-13 в 19 57 34

OctoberCMS 3.3.20: I get next data: [ string primary => 1, string section => 2, array 'custom_fields' => [] ]

OctoberCMS 3.5: I get an unpacked array of custom_fields; []

Dok2314 commented 11 months ago

Any news?!

daftspunk commented 11 months ago

Hi @Dok2314

Sometimes, unconventional code works because of a quirk in the design; when the quirk (bug) is fixed, the code breaks and forces you to write it according to the conventional design pattern.

In this case, your issue is probably because of the following change:

image

Here is the reason for the change:

When NestedForm is not in a relation mode, it currently doesn't process form widgets correctly and it just returns raw post data.

This causes wrong values to be stored in a database when using more complex form widgets. This PR ensures that data is correctly processed before it is returned from the getSaveValue method.

I'm not 100% sure if this is the problem with your code, but hopefully, it offers some insight into a recent change to NestedForm. If you think you've found a bug in the October CMS platform, please get in touch with the helpdesk.

Dok2314 commented 11 months ago

My model uses filterFields method, and in OctoberCMS 3.5, I fall into the method when i press "create", and due to changes in the getSaveValue method, I do not receive all the necessary data and get into the method, as a result I hide my own fields, before this did not happen, because all the necessary data came in. Use filterFields - it's not a unconventional code.

daftspunk commented 11 months ago

You should be able to access via post() in filterFields, hopefully it helps as a workaround.