Datatable wrong data-field-name if field name with key, and data dont save
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 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.
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.
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
In fields.yaml:
fields:
content:
label: Content
type: datatable
columns:
field1:
title: Code
field2:
title: Title
field3:
title: Title

^ 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?
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 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.
@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?
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.
Still actual. The example was provided as PR to Test plugin.
@Trysystems could you link the PR here?
https://github.com/wintercms/wn-test-plugin/pull/5
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.
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.
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.
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.
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.
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].
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].
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].
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].