Closed volodymyrss closed 7 months ago
It's more complicated than I thought. The way @motame proposed in https://github.com/oda-hub/mmoda-frontend-module/issues/197 is following the PHP convention of adding square brackets to the names of the form fields to form-encode complex data structures. But Flask doesn't follow this convention.
If we stick to this convention, the needed adaptations are:
request.form.getlist
where needed. It could be quite complicated to implement a general enough case. oda_api
will also require changes: constructing properly named request parameters from a structured data. More natural approach is to send structured parameters json-encoded. This still requires adaptations to dispatcher and oda_api, but they seem to be way more straightforward. On the other hand, this requires some JS on the frontend side to encode this argument before submitting the form. Is it achievable, @motame?
Yes, it's possible to send the whole parameters as one json object instead. I'll implement it soon and let you know.
@dsavchenko, do you prefer only the parameter filters as JSON object or the whole parameters within one JSON object ?
I think, encoding all parameters in one json object will be rather backwards-incompatible change. Whereas, for this single new type of parameters - it's feasible. We can further discuss today
Yeah indeed, let us do that for all "array" parameters only.
The new feature has been implemented. The multi-valued parameters (fields) are sent as JSON strings to the server. See attached screenshot for an example
Pushed to the branch euclid-filter-select-ui (linked to this issue)
Cool! Thanks!
This requires adding the jquery.serializeJSON
library to https://github.com/oda-hub/mmoda-frontend-drupal, right?
Oups ! sorry, I forgot to mention that. Indeed, yes. It is added under sites/all/libraries ...
sites/all/libraries$ ls -l jquery.serializeJSON
total 104
-rw-rw-r-- 1 meharga www-data 635 Jan 15 17:32 bower.json
-rw-rw-r-- 1 meharga www-data 5716 Jan 15 17:32 CHANGELOG.md
-rw-rw-r-- 1 meharga www-data 15614 Jan 15 17:32 jquery.serializejson.js
-rw-rw-r-- 1 meharga www-data 4635 Jan 15 17:32 jquery.serializejson.min.js
-rw-rw-r-- 1 meharga www-data 1077 Jan 15 17:32 LICENSE.txt
-rw-rw-r-- 1 meharga www-data 969 Jan 15 17:32 package.json
-rw-rw-r-- 1 meharga www-data 34782 Jan 15 17:32 package-lock.json
-rw-rw-r-- 1 meharga www-data 19450 Jan 15 17:32 README.md
drwxrwxr-x 3 meharga www-data 4096 Jan 15 17:32 spec
git clone https://github.com/marioizquierdo/jquery.serializeJSON.git
This basically works, but it relies on the hardcoded parameter name "filter", whereas with nb2workflow plugin the name of this table parameter may be arbitrary.
Both validation code and json-encoding should rely on e.g. class
https://github.com/oda-hub/mmoda-frontend-module/issues/197