How to store multiple values in one database cell?
How to store multiple values in one database cell?
Dear Community
I have recently started using Datatables Editor for an upcoming project and am strugling with a few issues when using the editor.
The project is hosted on Typo3 CMS, which has a single usergroups field for all users. This field containds the ID of the usergroup(s) for that user. It is possible that only a single usergroup is selected for a user, but multiple can be present as well. The usergroups are separated by ",".
I tried using the following
Field::inst( 'usergroup' )
->setFormatter( 'Format::implode', "," )
->getFormatter( 'Format::explode', "," )
However when I select multiple groups and submit, I get a JavaScript error even before the data is sent ("TypeError: e is null"). I assume that the problem is that the Editor does not know that my select field can have multiple values.
I have the usergroups field set for "select" and "opts" "multiple" is enabled.
These settings work fine with actual multiple-type fields (in case of linked joins), but fails in this supposedly more simple case. Could you plesae give me an example on how to solve this?
This question has an accepted answers - jump to answer
Answers
The
select
field type uses jQuery's$().val()
method to read the value, and that does work okay with a multiple value select field type - it returns an array of the selected values.So there is something else going on. Are you able to give me a link to the page so I can debug the issue?
Thanks,
Allan
Dear allan
I do not think I can provide you with a link, but I can paste the whole generated JS code.
So the problem is related to "fe_users.usergroup".
Could you also give me the backtrace for the error ( TypeError: e is null ) so I can see where it is occurring in the code and what is calling the function that is causing the error.
Thanks,
Allan
Dear Allan
Sorry for my late reply, I have been very busy as of late and this issue was set on halt in favour for more important bits.
EDIT:
I removed some parts of this post, becasue it became invalid.
I was able to make fast progress with this. It turns out that the usergroups was not the source of the issue afterall (even though it only ever appeared when I selected more then one usergroup).
The actual cause appears to be with the "crm_egyeb_teruletek" field.
Right now the datatable works good if "crm_egyeb_teruletek" is set to checkbox, but fails when I try to set it to a multiple select.
This field is link-joined with another table (based on one of the examples here). In the examples it works as checbox too, but in my case there are too many selectable options, so I need a select box.
On a different topic:
is it possible to filter (add where clause) a table inside leftjoin statement in the editor?
So are you still getting an error on the page? If so, can you give me a backtrace?
The
where()
condition can be applied to the joined fields as well, yes. It's just a case of adding the column name in the condition.Allan