winter icon indicating copy to clipboard operation
winter copied to clipboard

Datatable wrong data-field-name if field name with key, and data dont save

Open Trysystems opened this issue 4 years ago • 20 comments

Datatable widget generates wrong attribute data-field-name. In my case, I extend form with fields with keys (data[1][row], data[2][row]), and widget generates name "Report[data[1][row]]". It's because of logic on 155 string at DataTable.php file.

Temporary fix it with change string to $config->fieldName = $this->getParentForm()->arrayName.'['.implode('][', HtmlHelper::nameToArray($this->fieldName)).']';

I took logic from FormField class.

Trysystems avatar Apr 26 '21 07:04 Trysystems

@Trysystems I believe it is set up this way because the data table was originally built for the Builder plugin (I believe?) and that's the format it used. Since it's been like this for years, it may be difficult to make any changes to the naming without breaking implementations of this data type already out there, but we'll look into it further.

bennothommo avatar Apr 26 '21 13:04 bennothommo

Thank you. This fix shouldn't break anything because "Report[data[1][row]]" wrong structure of field name and it can't work at all, because table.js use this name to create post data, and with wrong name data loses.

Trysystems avatar Apr 26 '21 17:04 Trysystems

Some backtracking information (may be useful for someone to make PR or test things) - mentioned code part which may contain problem for this issue was introduced in https://github.com/wintercms/winter/commit/970d5622c0deeaeef38c618b42d43b82499fd7f2 as a fix for https://github.com/octobercms/october/issues/4063

arvislacis avatar May 03 '21 07:05 arvislacis

In fields.yaml:

fields:
    content:
        label: Content
        type: datatable
        columns:
            field1:
                title: Code
            field2:
                title: Title
            field3:
                title: Title

2021-05-03_11-58

^ I made this just for testing purposes and works fine for me. I understand that this is not the format issue author is using but may I ask @Trysystems why you use so specific keys like data[1][row] and data[2][row] ? Can't you reduce that to similar example I mentioned?

arvislacis avatar May 03 '21 09:05 arvislacis

fields:
    content[table]:
        label: Content
        type: datatable
        columns:
            field1:
                title: Code
            field2:
                title: Title
            field3:
                title: Title

This will give you data-field-name="Model[content[table]]" attribute now. And js script cant push to server correct data, so you'll receive model[content] empty array.

Trysystems avatar May 05 '21 04:05 Trysystems

@Trysystems True but why can't you simply use content or table as the field name of datable field so you could avoid using nested name in the first place?

In my opinion field name is a field name, that's the reason why it's treated like single value. I also couldn't find any references to your mentioned cases for any other form field in https://wintercms.com/docs/backend/forms

Also make sure that you have set your datatable field as jsonable field in your model (property protected $jsonable = [];) because I assume that you would want to store all datatable data into one single text field of database row.

arvislacis avatar May 05 '21 05:05 arvislacis

@Trysystems we have examples of the data table working in the Test plugin without these changes. Are you able to demonstrate in a PR to the Test plugin an implementation that does result in data loss?

bennothommo avatar May 06 '21 02:05 bennothommo

This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

github-actions[bot] avatar Jul 06 '21 00:07 github-actions[bot]

Still actual. The example was provided as PR to Test plugin.

Trysystems avatar Jul 06 '21 01:07 Trysystems

@Trysystems could you link the PR here?

LukeTowers avatar Jul 06 '21 02:07 LukeTowers

https://github.com/wintercms/wn-test-plugin/pull/5

Trysystems avatar Jul 06 '21 02:07 Trysystems

This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

github-actions[bot] avatar Sep 05 '21 00:09 github-actions[bot]

This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

github-actions[bot] avatar Nov 05 '21 00:11 github-actions[bot]

This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

github-actions[bot] avatar Jan 05 '22 00:01 github-actions[bot]

This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

github-actions[bot] avatar Mar 07 '22 00:03 github-actions[bot]

This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

github-actions[bot] avatar May 07 '22 00:05 github-actions[bot]

This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at [email protected].

github-actions[bot] avatar Nov 06 '22 00:11 github-actions[bot]

This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at [email protected].

github-actions[bot] avatar May 08 '23 00:05 github-actions[bot]

This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at [email protected].

github-actions[bot] avatar Nov 08 '23 00:11 github-actions[bot]

This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at [email protected].

github-actions[bot] avatar May 10 '24 00:05 github-actions[bot]