'FullCalendar sends array in single query param, Rails expects repeated param per array value
In Rails 6 and FullCalendar v5.11, when passing form parameters in FullCalendar's addEventSource() method via extraParams, array parameters are added to the url query string in a single parameter rather than repeated per value as expected by Rails.
E.G. with extraParams: { "staff_id[]": ["123", "139"] },
FullCalendar adds it to the url in the form:
staff_id[]=123,139
but Rails requires it in the query string as:
staff_id[]=123&staff_id[]=139
Any suggestions on how to get FullCalendar to send arrays in the query string format expected by Rails?
There are multiple filters so it is awkward to wrestle the strings from Rails params back into arrays in the controller (in this example the controller Parameters receive "staff_id"=>["123,139"] instead of "staff_id"=>["123", "139"])
Update: jQuery.get() generates url parameters in the form key[]=1&key[]=2, as required by Rails controllers, for arrays in its data argument. Can FullCalendar be made do the same?
Update: FullCalendar's encodeParams() function is responsible for this:
function encodeParams(params) {
var parts = [];
for (var key in params) {
parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]));
}
return parts.join('&');
}
Overwriting this code locally with jQuery.param(params) works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
